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 <https://github.com/Genymobile/scrcpy/issues/4115>
This commit is contained in:
parent
808bd14e30
commit
85b55b3c4e
1 changed files with 3 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue