Bossgaming099 / ctypes-opencv

Automatically exported from code.google.com/p/ctypes-opencv
0 stars 0 forks source link

Fix for crash at process termination with open windows with trackbars #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
So I had a little time tonight to look into the crashes at the end of demos
that weren't closing all their own windows (such as edge.py).  I narrowed
it down to cases where a trackbar was created.  

My suspicion is that the interpreter cleanup is getting rid of the ctypes
objects cached in _windows_callbacks earlier than the highgui window
destruction and something in the OpenCV highgui module tries to reference
them.  I can't identify a precise case looking at the OpenCV code (and I
tried even without a value pointer or callback), but adding an atexit to
the highgui module that destroys all windows early in the interpreter
shutdown fixes the crash, so I'm thinking it's a reasonable thing to do.

Along the way I discovered that the current cvCreateTrackbar can't actually
create trackbars without a callback - None doesn't pass the ctypes
parameter check for a callback function.  So based on an old ctypes mailing
list thread, I defined a NULL pointer value cast to the callback type that
is permitted, and use that when no callback is specified.

-- David

Original issue reported on code.google.com by db3l.em...@gmail.com on 12 Jan 2009 at 8:36

Attachments:

GoogleCodeExporter commented 8 years ago
I also ran into a crash with the demos not having a cvDestroy*() at exit. I was
actually searching the Python help file to find a way to implement a module
destructor when I saw this patch. It solves the problem nicely. Patched. 
Thanks. 

Original comment by pmtri80@gmail.com on 14 Jan 2009 at 2:30