Deleting vtkoutputwindows used by SetInstance

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Deleting vtkoutputwindows used by SetInstance

Mwoua
Hello,
I'm using Qt + VTK on windows.

When I open my VTK window I redirect vtk error message using (in my constructor)
 
        vtkSmartPointer<CustomOutputWindow> lOutputWindow = vtkSmartPointer<CustomOutputWindow>::New();
        vtkOutputWindow::SetInstance(lOutputWindow);
        lOutputWindow->Delete(); // now SetInstance owns the reference

So when I close my window, I have nothing that is using VTK left, so I would like to delete my output window. (calling Delete() cause a read access violation)

Also, if I try to call SetInstance again, with another CustomOutputWindow, I also have a read access violation (vtkOutputWindow::Instance->Delete(); in file vtkOutputWindow.cxx)

How can I delete my object?


PS : setinstance also prevent my display from working on an older computer, if I dont use it, I have a message saying that the chipset is old and might not work, but besides that it works. If I try to use setinstance, the display does not work.

Thanks,
David
Reply | Threaded
Open this post in threaded view
|

Re: Deleting vtkoutputwindows used by SetInstance

Shawn Waldon-2
Hi David,

I suspect the problem is that you are creating a VTK smartpointer and then deleting the object yourself (to transfer ownership according to the comment).  But when the vtkSmartPointer on the stack is deleted it calls Delete() on the object it references.  So you are decrementing the reference count twice and cancelling the vtkOutputWindow's ownership of the object.  Remove the line IOutputWindow->Delete() and I think it will resolve the problem.

You can learn more about vtk's smart pointer here [1].

HTH,
Shawn

[1]: http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers

On Fri, Apr 14, 2017 at 3:46 PM, Mwoua <[hidden email]> wrote:
Hello,
I'm using Qt + VTK on windows.

When I open my VTK window I redirect vtk error message using (in my
constructor)

        vtkSmartPointer<CustomOutputWindow> lOutputWindow =
vtkSmartPointer<CustomOutputWindow>::New();
        vtkOutputWindow::SetInstance(lOutputWindow);
        lOutputWindow->Delete(); // now SetInstance owns the reference

So when I close my window, I have nothing that is using VTK left, so I would
like to delete my output window. (calling Delete() cause a read access
violation)

Also, if I try to call SetInstance again, with another CustomOutputWindow, I
also have a read access violation (vtkOutputWindow::Instance->Delete(); in
file vtkOutputWindow.cxx)

How can I delete my object?


PS : setinstance also prevent my display from working on an older computer,
if I dont use it, I have a message saying that the chipset is old and might
not work, but besides that it works. If I try to use setinstance, the
display does not work.

Thanks,
David



--
View this message in context: http://vtk.1045678.n5.nabble.com/Deleting-vtkoutputwindows-used-by-SetInstance-tp5742892.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Deleting vtkoutputwindows used by SetInstance

Mwoua
Thats what I figured so I worked around the issue and allowed only one instance of my class. That's not what I wanted, but I can live with that.

But is there a way to force a reinitialization of the instance, so it can destruct my object?

Also a weird thing about my issue on the older computer, using setinstance with a NOT smartpointer work, but it doesnt with a smartpointer. Other smartpointer are working fine in the same class.
Reply | Threaded
Open this post in threaded view
|

Re: Deleting vtkoutputwindows used by SetInstance

Mwoua
Mwoua wrote
But is there a way to force a reinitialization of the instance, so it can destruct my object?

Also a weird thing about my issue on the older computer, using setinstance with a NOT smartpointer work, but it doesnt with a smartpointer. Other smartpointer are working fine in the same class.
It was too early in the morning, I just need to call setinstance(nullptr).

The weird behaviour with setinstance(smartpointer) on the older computer is still valid though