From 34b620c3f86cb2b5adf11440cdf79a3cec216269 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Sat, 17 Jan 2026 15:43:04 -0500 Subject: [PATCH] event: Only consider topmost windows when generating SDL_QUIT Otherwise, the quit event can be sent prematurely. The topmost status must be queried and cached before sending the close request event, as the window may be destroyed in an event handler. --- src/events/SDL_windowevents.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index c308e7ca72..1f8a9615ba 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -228,6 +228,9 @@ bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data post_event = false; } + // The window might be destroyed in an event handler, so cache the topmost status first. + const bool window_is_topmost = !window->parent; + // Post the event, if desired SDL_Event event; event.type = windowevent; @@ -301,7 +304,7 @@ bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data } } - if (windowevent == SDL_EVENT_WINDOW_CLOSE_REQUESTED && !SDL_HasActiveTrays()) { + if (windowevent == SDL_EVENT_WINDOW_CLOSE_REQUESTED && window_is_topmost && !SDL_HasActiveTrays()) { int count = window ? 0 : 1; for (SDL_Window *n = _this->windows; n; n = n->next) { if (!n->parent && !(n->flags & SDL_WINDOW_HIDDEN)) {