[PATCH][SDL-v1.3] Fix lost focus event to destroyed window

Attached is a quick fix to avoid the use of a window pointer after the
window was destroyed.
This was caught on Linux, affecting at least 3 different versions of
Ubuntu (8.04, 10.04 and 11.10).

The problem is that after the window is destroyed,
SDL_OnWindowFocusLost() is invoked, using an already freed pointer.

I have to say I don’t think this is the ideal patch. The problem is in
having global variables holding pointers to structures with a shorter
lifespan.
The proper patch is probably to change the SDL_Keyboard and similar
structures to hold a window ID, instead of a pointer, and checking the
value of SDL_GetWindowFromID() before using it.

As I’m not familiar enough with the SDL code, this patch works for me,
but the above stands.

My guess as for why this was not caught on other systems is that maybe
the focus lost events are generated at the SDL_HideWindow() time,
which is done before the actual window structure release, but on Linux
(X11) those events are only triggered later.

Regards,
~Nuno Lucas
-------------- next part --------------
A non-text attachment was scrubbed…
Name: libsdl2-fix-focus-after-destroy.diff
Type: text/x-patch
Size: 584 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111108/a2835230/attachment.bin