From 76560f9e47aff29ecbefd4f0b29bc3c7f96d2219 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 27 May 2026 13:07:46 -0700
Subject: [PATCH] Revert "android: fixed a possible joystick-related deadlock
on application termination"
This reverts commit 6b4ae6846017b4afcde8f91c7d1bd2e2512c0ff8.
It turns out this deadlock is possible for any joystick event delivery combined with an event watcher that locks joysticks. I'm reverting this change for now, and will be working on a better global solution for this problem.
---
src/video/android/SDL_androidevents.c | 22 ----------------------
1 file changed, 22 deletions(-)
diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c
index 605591b990f57..4bdd717e121fe 100644
--- a/src/video/android/SDL_androidevents.c
+++ b/src/video/android/SDL_androidevents.c
@@ -178,26 +178,6 @@ static void Android_OnDestroy(void)
static void Android_HandleLifecycleEvent(SDL_AndroidLifecycleEvent event)
{
- // Make sure we're holding the joystick lock before dispatching life cycle events
- // This prevents deadlocks of this form:
- // 1. SDL locks the event watch list to dispatch the lifecycle event
- // 2. a joystick sensor event arrives, taking the joystick lock
- // 3. the lifecycle event dispatch calls into the application event
- // watcher, which closes joysticks, trying to take the joystick lock
- // 4. SDL delivers the sensor event, trying lock the event watch list
- // 5. BOOM, deadlock!
- //
- // There are a few solutions to this, most of which involve unlocking the
- // event watch list while delivering events or unlocking the joystick lock
- // while delivering joystick events, both of which reduce performance and
- // are extremely risky, so we'll do this, which is the least risky option.
- //
- // If you end up needing to wait for another thread that handles joystick
- // events in your life cycle handling, then you can simply unlock joysticks,
- // wait for that thread to complete, and then re-lock joysticks.
-
- SDL_LockJoysticks();
-
switch (event) {
case SDL_ANDROID_LIFECYCLE_WAKE:
// Nothing to do, just return
@@ -217,8 +197,6 @@ static void Android_HandleLifecycleEvent(SDL_AndroidLifecycleEvent event)
default:
break;
}
-
- SDL_UnlockJoysticks();
}
static Sint64 GetLifecycleEventTimeout(bool paused, Sint64 timeoutNS)