[vtkusers] Debugging a Segfault
Peter F Bradshaw
pfb at exadios.com
Mon Apr 3 09:52:21 EDT 2006
Hi;
On Sat, 1 Apr 2006, Martin Baumann wrote:
> Hi,
>
> thanks for your help!
> I checked my source files for Register() function calls: there aren't any.
You should not look for Register()s. You should look for a Delete() which
are not matched by a corresponding New() or Register(). In general you
should Delete() only those objects which you have created or
registered.
> Is there a way that does register object implicitely?
Not that I know of. This would be sone srt of "auto pointer"
functionality. AFAIK reference counting / object life time must be
handled explicitly and manually. And some care needs to be exercised
in this regard.
>
> 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
> >
> >
> >
>
Cheers
--
Peter F Bradshaw, http://www.exadios.com, ICQ 75431157 (exadios).
Public key at www.exadios.com/pfb.pgp.key and www.exadios.com/pfb.gpg.key
Personal site: http://personal.exadios.com.
"I love truth, and the way the government still uses it occasionally to
keep us guessing." - Sam Kekovich.
More information about the vtkusers
mailing list