[vtk-developers] VTK SetPoints Error

Ragu Vijaykumar ragu at myosight.org
Sun Dec 19 15:10:24 EST 2010

Thanks for the reply! The problem seems to be in the actual SetPoints method though, which dereferences the parameter points. On the contrary, SetFieldData() and SetVerts() work exactly as expected, i.e. they increase the reference count of the passed parameter and so the Delete fxn works to properly memory manage. I tested that by moving the field data and cells lines above the point data. 

While syntactically the same, for some reason, the SetPoints line always crashes my program, and when examining the variable "points" in debugging mode, it gets instantiated correctly with refCount 1, and then SetPoints just sets the ref count to 0. Another weird thing is with the following code:

>> 	vtkPoints* points = vtkPoints::New(); // Ref Count  = 1
			 points->Register(NULL);   // Ref Count = 2
>> 	model->SetPoints(points); // Ref Count = 0!!!!!
>> 	points->Delete(); // PROGRAM CRASHES

I just wanted to try to increase the reference count of "points" to see whether the SetPoints method was automatically reducing the reference count by 1. If it was, then the SetPoints method should make points have a refCount of 1, but it still makes it 0 for some reason, and thus my program still crashes.

I should mention that the original code sample I sent fully compiles and executes properly under VTK 5.4.2 in OSX, 64 bit. This is only a program error in VTK 5.6.1, which is why I mentioned the detailed library compilation I used to build VTK earlier. I am in particular worried about taking out the -fobjc-gc line in the CMake settings, VTK_REQUIRED_OBJCXX_FLAGS:STRING="", leaving it blank instead so that I could get it to work with Qt 4.7.1. I built VTK with Cocoa, static libraries, and x86_64 architecture.


On Dec 19, 2010, at 11:48 AM, Ignaz Reicht wrote:

> Hv u tried using vtkSmartpointers instead of "Common"pointers? When using them u don't hv to Care about deleting Pointers. 
> Am 19.12.2010 um 12:12 schrieb Ragu Vijaykumar <ragu at myosight.org>:
>> Hi all,
>> This is my first time posting to this list, so I hope someone out there can help me. I have the following code that needs to create a model that I will specify. I am using VTK 5.6.1 under OSX 10.6.5 with Cocoa build and RelWithDebInfo, linked with Qt 4.7, and 
>> VTK_REQUIRED_OBJCXX_FLAGS:STRING="" to get it to work with Qt.
>> The issue lies with the SetPoints method, which seems to automatically delete the parameter 'Points'. I stepped through the debugger, and it shows that the method makes points reference count 0 from 1, while the fielddata and cells lines all work as expected. My program crashes on 'points->Delete' everytime, and I'm not sure why?
>> 	vtkPolyData* model = vtkPolyData::New();
>> 	cout << model->GetPoints() << endl;
>> 	vtkPoints* points = vtkPoints::New();
>> 	model->SetPoints(points);
>> 	points->Delete();
>> 	vtkFieldData* fieldData = vtkFieldData::New();
>> 	model->SetFieldData(fieldData);
>> 	fieldData->Delete();
>> 	vtkCellArray* cells = vtkCellArray::New();
>> 	model->SetVerts(cells);
>> 	cells->Delete();	
>> Ragu
>> _______________________________________________
>> Powered by www.kitware.com
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtk-developers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20101219/b1fc2d16/attachment.html>

More information about the vtk-developers mailing list