-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Please, before submitting a new issue verify and check:
- I tested it on latest raylib version from master branch
- I checked there is no similar issue already reported
- I checked the documentation on the wiki
- My code has no errors or misuse of raylib
Issue description
The touch position of first touch point is seemingly overwritten by some other coordinate when the touch point (=my finger) is not moving. When multiple touch points exists, the coordinates of the other touch points are correct. I modified the rcore_desktop_sdl.c file with logging to illustrate the issue:
Project code:
for (int i=0; i < GetTouchPointCount(); i++)
{
Vector2 pointerPosition = GetTouchPosition(i);
TraceLog(LOG_INFO, "Touch %f %f %d %d", pointerPosition.x, pointerPosition.y,
GetTouchX(), GetTouchY());
}Modified rcore_desktop_sdl.c file for debugging, in UpdateTouchPointSDL function:
CORE.Input.Touch.pointCount = SDL_GetNumTouchFingers(event.touchId);
for (int i = 0; i < CORE.Input.Touch.pointCount; i++)
{
SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i);
CORE.Input.Touch.pointId[i] = finger->id;
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width;
CORE.Input.Touch.position[i].y = finger->y*CORE.Window.screen.height;
TRACELOG(LOG_WARNING, "CORE.INPUT touch index %i: id=%i x=%f y=%f", i, finger->id, finger->x*CORE.Window.screen.width, finger->y*CORE.Window.screen.height);
CORE.Input.Touch.currentTouchState[i] = 1;
}Output:
WARNING: CORE.INPUT touch index 0: id=14863 x=681.000000 y=427.000000
WARNING: CORE.INPUT touch index 1: id=14864 x=692.000000 y=251.999985
WARNING: CORE.INPUT touch index 0: id=14863 x=681.000000 y=427.000000
WARNING: CORE.INPUT touch index 1: id=14864 x=692.000000 y=251.999985
INFO: Touch 681.000000 427.000000 681 427
INFO: Touch 692.000000 251.999985 681 427
INFO: Touch 0.000000 0.000000 0 0
INFO: Touch 692.000000 251.999985 0 0
INFO: Touch 0.000000 0.000000 0 0
INFO: Touch 692.000000 251.999985 0 0
INFO: Touch 0.000000 0.000000 0 0
INFO: Touch 692.000000 251.999985 0 0
INFO: Touch 0.000000 0.000000 0 0
The logs show how on the first frame after the touch event the coordinates of both touches are correct. But after that frame, the touch coordinate of the first point is reset. The log shows the state before mouse movement was registered - once I move the mouse, the coordinate of the first touch point is reset to the mouse position.
I assume this is some special handling to emulate mouse / touch positions that is not handled correctly.
Environment
- Windows 11
- AMD Ryzen AI 9 HX 370
- Radeon 890M, 2000 MHz
Issue Screenshot
Code Example
A simple demo main function to reproduce the GIF:
int main()
{
InitWindow(800, 600, "Touch SDL bug demo");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
for (int i=0; i < GetTouchPointCount(); i++)
{
Vector2 touchPos = GetTouchPosition(i);
DrawCircleV(touchPos, 100, BLUE);
DrawText(TextFormat("Touch %d: %g %g", i, touchPos.x, touchPos.y), touchPos.x, touchPos.y, 20, BLACK);
}
Vector2 mousePos = GetMousePosition();
DrawLine(mousePos.x - 100, mousePos.y - 100, mousePos.x + 100, mousePos.y + 100, RED);
DrawLine(mousePos.x - 100, mousePos.y + 100, mousePos.x + 100, mousePos.y - 100, RED);
EndDrawing();
}
CloseWindow();
}