From b5d7147786ef1016b5984130b225be71c816c194 Mon Sep 17 00:00:00 2001 From: mooff Date: Wed, 21 Feb 2024 20:29:45 +0000 Subject: [PATCH] Fix SDL multitouch tracking 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 2e2d190cb..4767dd07f 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -956,6 +956,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