Skip to content

Fixed bug #13493: Assertion failure at SDL_AddTouch with Android API 28 #13716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/android/SDL_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeAddTouch)(
{
const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);

SDL_AddTouch((SDL_TouchID)touchId, SDL_TOUCH_DEVICE_DIRECT, utfname);
SDL_AddTouch(Android_ConvertJavaTouchID(touchId),
SDL_TOUCH_DEVICE_DIRECT, utfname);

(*env)->ReleaseStringUTFChars(env, name, utfname);
}
Expand Down
25 changes: 20 additions & 5 deletions src/video/android/SDL_androidtouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ void Android_QuitTouch(void)
{
}


SDL_TouchID Android_ConvertJavaTouchID(int touchID)
{
SDL_TouchID retval = touchID;

if (touchID < 0) {
// Touch ID -1 appears when using Android emulator, eg:
// adb shell input mouse tap 100 100
// adb shell input touchscreen tap 100 100
//
// Prevent to be -1, since it's used in SDL internal for synthetic events:
retval -= 1;
} else {
// Touch ID 0 is invalid
retval += 1;
}
return retval;
}

void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
{
SDL_TouchID touchDeviceId = 0;
Expand All @@ -56,11 +75,7 @@ void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_fin
return;
}

/* Touch device -1 appears when using Android emulator, eg:
* adb shell input mouse tap 100 100
* adb shell input touchscreen tap 100 100
*/
touchDeviceId = (SDL_TouchID)(touch_device_id_in + 2);
touchDeviceId = Android_ConvertJavaTouchID(touch_device_id_in);

// Finger ID should be greater than 0
fingerId = (SDL_FingerID)(pointer_finger_id_in + 1);
Expand Down
1 change: 1 addition & 0 deletions src/video/android/SDL_androidtouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
extern void Android_InitTouch(void);
extern void Android_QuitTouch(void);
extern void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
extern SDL_TouchID Android_ConvertJavaTouchID(int touchID);
Loading