From 85b55b3c4e3b05c155225e035c4a9544f8864268 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 27 Jun 2023 18:38:10 +0200 Subject: [PATCH] Fix possible division by zero On sway (a window manager), SDL_WINDOWEVENT_EXPOSED and SDL_WINDOWEVENT_SIZE_CHANGED might not be called before a mouse event is triggered. As a consequence, the "content rectangle" might not be initialized when the mouse event is processed, causing a division by zero. To avoid the problem, initialize the content rect immediately when the window is shown. Fixes #4115 --- app/src/screen.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/screen.c b/app/src/screen.c index 2724a266..5b7a8808 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -488,6 +488,7 @@ sc_screen_show_initial_window(struct sc_screen *screen) { } SDL_ShowWindow(screen->window); + sc_screen_update_content_rect(screen); } void @@ -848,6 +849,8 @@ sc_screen_convert_drawable_to_frame_coords(struct sc_screen *screen, int32_t w = screen->content_size.width; int32_t h = screen->content_size.height; + // screen->rect must be initialized to avoid a division by zero + assert(screen->rect.w && screen->rect.h); x = (int64_t) (x - screen->rect.x) * w / screen->rect.w; y = (int64_t) (y - screen->rect.y) * h / screen->rect.h;