From 94c79917e3b68fbed3ff4a3920edc9d093b11c4f Mon Sep 17 00:00:00 2001 From: mooff Date: Thu, 29 Feb 2024 17:30:38 +0000 Subject: [PATCH] Fix SDL multitouch tracking (#3810) The fingerId from SDL was used as an index into the CORE.Input.Touch arrays, but it's an opaque / arbitrary int64, way bigger than MAX_TOUCH_POINTS, so the first non-simulated touch event would segfault. --- src/platforms/rcore_desktop_sdl.c | 44 ++++++++++++++----------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index f567119ed..1b6304d28 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -971,6 +971,23 @@ void SetMouseCursor(int cursor) CORE.Input.Mouse.cursor = cursor; } +static void UpdateSDLTouchPoints(SDL_TouchFingerEvent event) +{ + CORE.Input.Touch.pointCount = SDL_GetNumTouchFingers(event.touchId); + + for (int i=0; iid; + CORE.Input.Touch.position[i].x = finger->x * CORE.Window.screen.width; + CORE.Input.Touch.position[i].y = finger->y * CORE.Window.screen.height; + CORE.Input.Touch.currentTouchState[i] = 1; + } + + for (int i=CORE.Input.Touch.pointCount; i