[vtkusers] Debugging a Segfault
Martin Baumann
mailsgetlost at web.de
Sat Apr 1 10:36:25 EST 2006
Hi,
thanks for your help!
I checked my source files for Register() function calls: there aren't any.
Is there a way that does register object implicitely?
K.B.
Peter F Bradshaw schrieb:
>Hi;
>
>On Fri, 31 Mar 2006, Martin Baumann wrote:
>
>
>
>>Hi,
>>
>>I am using KDbg. I guess that I did what you meant:
>>
>>
>
>I'm unfamiliar with both KDbg and Kdbg but I imagine that it is a gdb
>front end.
>
>
>
>>I set a stop point on the line that causes the error. I opened the
>>window that show the local variables.
>>Next to _plane_widget stands 0x832aee0. So not 0.
>>
>>
>
>Ok. I suspect that the VTK library you are linking to has been compiled
>without symbols. If this is the case the segfault is actually occuring
>within vtkPlaneWidget::Delete().
>
>One of the more common causes of a segfault in the dtor is that an
>object that the class wants to manage is deleted from underneath it.
>That is, a pointer to an object managed by vtkPlaneWidget is obtained
>but Register() is not called on it and, subsequently, has Delete()
>called on it. This will cause problems within the managing object's
>Delete() (if not before). It might be worth while to scan the code that
>uses any object pointers obtained from _plane_widget to ensure that
>something like this is not occuring.
>
>
>
>>To make sure _plane_widget is referenced only once I did the following:
>> std::cout << "LW: " << _line_widget->GetReferenceCount() << std::endl;
>> _line_widget ->Delete();
>> std::cout << "PW: " << _plane_widget->GetReferenceCount() << std::endl;
>>_plane_widget->Delete(); // This causes the SIGFAULT
>>
>>This lead to the following output:
>> LW: 1
>> PW: 1
>>
>>Hmmm...
>>
>>Thanks, M.B.
>>
>>
>>Peter F Bradshaw schrieb:
>>
>>
>>
>>>Step one is to determine the value of _plane_widget. My guess is that it
>>>is 0 (i.e. 0x0). The value of _plane_widget may be examined by
>>>"printing" it - however that's done in Kdbg. Using gdb you would type:
>>>
>>>p _plane_widget
>>>
>>>in the context of the segfault.
>>>
>>>The reason that _plane_widget may be zero is because it was initally
>>>asigned that value when it was declared and there has been no
>>>
>>>_plane_widget = vtkPlaneWidget::New();
>>>
>>>However, as you point out, it may be that you are deleting an object
>>>that no longer exists. That is it has been deleted elsewhere. You can
>>>examine the reference count of _plane_widget at any time by something
>>>like:
>>>
>>> cout << _plane_widget->GetReferenceCount() << endl;
>>>
>>>If the value of GetReferenceCount() is 1 just before Delete() then the
>>>Delete() will really delete the object.
>>>
>>>Vtk reference counting is normally handled in vtkObjectBase (assuming
>>>no overloading).
>>>
>>>
>>>
>
>Cheers
>
>
>
More information about the vtkusers
mailing list