From 9493e6974f70a906950c9d8196c9a9982300f261 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 7 Aug 2024 12:15:48 -0700 Subject: [PATCH] Validate window pointer before sending events for it If there are bugs it's possible that the window pointer is invalid. Double check it before sending the application events and potentially dereferencing it. This showed up in https://github.com/libsdl-org/SDL/issues/10494 as a window getting mouse focus as it was being destroyed and then crashing later when mouse focus was set to a different window. --- src/events/SDL_windowevents.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index 262f3da27..0dd7e4a0f 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -43,7 +43,7 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, { int posted; - if (!window) { + if (!SDL_ObjectValid(window, SDL_OBJECT_TYPE_WINDOW)) { return 0; } if (window->is_destroying && windowevent != SDL_EVENT_WINDOW_DESTROYED) {