[vtkusers] vtkCocoaRenderWindowInteractor - memory violation when dealloc

Boxer, Aaron Aaron.Boxer at uhn.ca
Wed Jan 29 09:01:12 EST 2014


David,
I tried the smart pointers, but I get the same error.

(I am using the master branch to build VTK, by the way)


Here is how I allocate and dealloc these objects (no smart pointers, just original code)

    if ( self = [super initWithFrame:frame])
	{
	_renderer = vtkOpenGLRenderer::New();
		_cocoaRenderWindow = vtkCocoaRenderWindow::New();
		_cocoaRenderWindow->SetWindowId( [self window]);
		_cocoaRenderWindow->SetDisplayId( self);

		_cocoaRenderWindow->AddRenderer(_renderer);
	_interactor = vtkCocoaRenderWindowInteractor::New();
		_interactor->SetRenderWindow(_cocoaRenderWindow);

		vtkInteractorStyleTrackballCamera *interactorStyle;
		interactorStyle = vtkInteractorStyleTrackballCamera::New();
		_interactor->SetInteractorStyle( interactorStyle );
		interactorStyle->Delete();

	[self setVTKRenderWindow:_cocoaRenderWindow];

	_interactor->Initialize();
    }

    return self;
}



-(void)dealloc
{
	NSLog( @"VTKView dealloc");

    _renderer->Delete();
	_cocoaRenderWindow->Delete();
	_interactor->Delete();
	[super dealloc];
}


Thanks,
Aaron



-----Original Message-----
From: David Cole [mailto:dlrdave at aol.com] 
Sent: Wednesday, January 29, 2014 7:48 AM
To: Boxer, Aaron; vtkusers at vtk.org
Subject: Re: [vtkusers] vtkCocoaRenderWindowInteractor - memory violation when dealloc

Hi Aaron,

You should only Delete objects that you created with New.

Did you create all 3 of these objects with New yourself? (Or did one or more of them come from getting the default object from the render
window....?)

Also, there's no need to *ever* call Delete if you use vtkSmartPointer and vtkNew. I'd strongly recommend using vtkSmartPointer from VTK client applications.


HTH,
David C.


This e-mail may contain confidential and/or privileged information for the sole use of the intended recipient. 
Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited. 
If you have received this e-mail in error, please contact the sender and delete all copies. 
Opinions, conclusions or other information contained in this e-mail may not be that of the organization.



More information about the vtkusers mailing list