Lagrange [dev]

App: Events posted early may cause a crash

=> e86da1f231c5adc637582f1a518fdade74579776

diff --git a/src/app.c b/src/app.c
index d4b2ab54..4eeae94e 100644
--- a/src/app.c
+++ b/src/app.c
@@ -689,7 +689,7 @@ static int resizeWatcher_(void *user, SDL_Event *event) {
             SDL_Event u = { .type = SDL_USEREVENT };
             u.user.code = command_UserEventCode;
             u.user.data1 = strdup("theme.changed");
-            u.user.windowID = SDL_GetWindowID(d->window->win);
+            u.user.windowID = id_Window(d->window);
             dispatchEvent_Widget(d->window->root, &u);
         }
 #endif
@@ -782,7 +782,7 @@ void postRefresh_App(void) {
         SDL_Event ev;
         ev.user.type     = SDL_USEREVENT;
         ev.user.code     = refresh_UserEventCode;
-        ev.user.windowID = get_Window() ? SDL_GetWindowID(get_Window()->win) : 0;
+        ev.user.windowID = id_Window(get_Window());
         ev.user.data1    = NULL;
         ev.user.data2    = NULL;
         SDL_PushEvent(&ev);
@@ -807,7 +807,7 @@ void postCommand_App(const char *command) {
     }
     ev.user.type     = SDL_USEREVENT;
     ev.user.code     = command_UserEventCode;
-    ev.user.windowID = get_Window() ? SDL_GetWindowID(get_Window()->win) : 0;
+    ev.user.windowID = id_Window(get_Window());
     ev.user.data1    = strdup(command);
     ev.user.data2    = NULL;
     SDL_PushEvent(&ev);
diff --git a/src/ui/window.c b/src/ui/window.c
index 7c16cf09..5101ed9b 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1042,6 +1042,10 @@ void setCursor_Window(iWindow *d, int cursor) {
     d->pendingCursor = d->cursors[cursor];
 }
 
+uint32_t id_Window(const iWindow *d) {
+    return d && d->win ? SDL_GetWindowID(d->win) : 0;
+}
+
 iInt2 rootSize_Window(const iWindow *d) {
     return d->root->rect.size;
 }
diff --git a/src/ui/window.h b/src/ui/window.h
index bdd4d008..8be8b88d 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -60,6 +60,7 @@ void        setUiScale_Window       (iWindow *, float uiScale);
 void        setFreezeDraw_Window    (iWindow *, iBool freezeDraw);
 void        setCursor_Window        (iWindow *, int cursor);
 
+uint32_t    id_Window               (const iWindow *);
 iInt2       rootSize_Window         (const iWindow *);
 float       uiScale_Window          (const iWindow *);
 iInt2       coord_Window            (const iWindow *, int x, int y);
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/dev/cdiff/e86da1f231c5adc637582f1a518fdade74579776
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
27.147634 milliseconds
Gemini-to-HTML Time
0.210272 milliseconds

This content has been proxied by September (ba2dc).