From 185bcb61145d4c339f1701010b582b77a7f6ef4b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 14 Jan 2012 01:38:11 -0500 Subject: [PATCH] Fixed bug 1238 - SDL_SetKeyboardFocus may send events to already destroyed windows bastien.bouclet@gmail.com 2011-06-26 02:15:36 PDT SDL_Keyboard::focus does not seem to be reset when the window that has focus is destroyed, resulting in the following crash : #0 X11_SetWindowGammaRamp (_this=0x8ed9cb0, window=0x91f25c0, ramp=0x0) at src/video/x11/SDL_x11window.c:948 #1 0x001bd15e in SDL_OnWindowFocusLost (window=0x91f25c0) at src/video/SDL_video.c:1900 #2 0x00168a2e in SDL_SendWindowEvent (window=0x91f25c0, windowevent=, data1=0, data2=0) at src/events/SDL_windowevents.c:157 #3 0x00166454 in SDL_SetKeyboardFocus (window=0x9678a08) at src/events/SDL_keyboard.c:612 --- src/video/SDL_video.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 055fc4eb8..c3e18964f 100755 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1932,6 +1932,17 @@ SDL_DestroyWindow(SDL_Window * window) CHECK_WINDOW_MAGIC(window, ); + /* Restore video mode, etc. */ + SDL_HideWindow(window); + + /* Make sure this window no longer has focus */ + if (SDL_GetKeyboardFocus() == window) { + SDL_SetKeyboardFocus(NULL); + } + if (SDL_GetMouseFocus() == window) { + SDL_SetMouseFocus(NULL); + } + /* make no context current if this is the current context window. */ if (window->flags & SDL_WINDOW_OPENGL) { if (_this->current_glwin == window) { @@ -1939,9 +1950,6 @@ SDL_DestroyWindow(SDL_Window * window) } } - /* Restore video mode, etc. */ - SDL_HideWindow(window); - if (window->surface) { window->surface->flags &= ~SDL_DONTFREE; SDL_FreeSurface(window->surface);