Page MenuHomePhabricator

Ellipsoid crash
Closed, ResolvedPublic


While porting to MITK 2018.04, our application crashes when I create an Ellipsoid. I always have the "Access Violation" error. I also tested with Cube, Cone and Cylinder and they are all ok. I investigated to find the problem and I know how to fix it but I don't know why it works. In the constructor of those 4 objects, we can find code that looks like that:

vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
... config sphere ...
} // end of scope -> CRASH

The last line (Delete) is useless because the object will be deleted anyway at the end of the scope. My app doesn't crash when I remove it. I'm surprised though because I thought that we could safely call Delete() without a crash at the end of scope. Since it does work for the other objects, I don't understand what's going on.

I didn't test on other platform but I know it crashes on Windows 10, VS 2017 in Debug and Release (silent, but my test doesn't show "OK").

Event Timeline

kislinsk triaged this task as Normal priority.Aug 23 2018, 11:56 PM
kislinsk edited projects, added MITK (2018-04); removed MITK.
kislinsk added a subscriber: kislinsk.

The difference between Ellipsoid and the other classes is the usage of a vtkSmartPointer in the former case instead of a raw pointer. Unfortunately, the one who changed the raw pointer to a smart pointer forgot to remove the call to Delete(). This makes a difference as SetVtkPolyData() calls TakeReference() to take ownership of the input and then manually calls Register() to increase the reference count to 2. Then, Delete() reduces it to 1 and when the sphere smartpointer goes out of scope the reference count is 0 and the object is deleted but to work as intended it should be 1 after the constructor.

kislinsk closed this task as Resolved.EditedAug 24 2018, 12:06 AM
kislinsk claimed this task.

Should be fixed in the beta branch now. I made a commit in your name (rMITK4fb32d1ab856: Fix wrong deletion), hope that's okay for you?