From 0e61c106f5649d355de3a851fdbf9280509435b5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 22 Aug 2022 12:49:41 -0700 Subject: [PATCH] Don't calculate relative mouse motion if we don't have a valid position Fixes https://github.com/libsdl-org/SDL/issues/1928 --- src/events/SDL_mouse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index ae85a0c1e..76433fc65 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -361,8 +361,8 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ { SDL_Mouse *mouse = SDL_GetMouse(); int posted; - int xrel; - int yrel; + int xrel = 0; + int yrel = 0; /* SDL_HINT_MOUSE_TOUCH_EVENTS: controlling whether mouse events should generate synthetic touch events */ if (mouse->mouse_touch_events) { @@ -416,7 +416,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ yrel = y; x = (mouse->last_x + xrel); y = (mouse->last_y + yrel); - } else { + } else if (mouse->has_position) { xrel = x - mouse->last_x; yrel = y - mouse->last_y; }