mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-13 07:03:54 +00:00
Fixed ABBA deadlock on Android
This fixes a deadlock when a call comes in from Java that takes the activity lock and then tries to send an event, which takes the event lock, at the same time the application thread takes the event lock and then calls SDL_RequestAndroidPermission(), which takes the activity lock. Fixes https://github.com/libsdl-org/SDL/issues/15772 Fixes https://github.com/libsdl-org/SDL/issues/15771
This commit is contained in:
@@ -3186,12 +3186,12 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePermissionResult)(
|
||||
JNIEnv *env, jclass cls,
|
||||
jint requestCode, jboolean result)
|
||||
{
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
SDL_LockMutex(SDL_event_lock);
|
||||
NativePermissionRequestInfo *prev = &pending_permissions;
|
||||
for (NativePermissionRequestInfo *info = prev->next; info != NULL; info = info->next) {
|
||||
if (info->request_code == (int) requestCode) {
|
||||
prev->next = info->next;
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
SDL_UnlockMutex(SDL_event_lock);
|
||||
info->callback(info->userdata, info->permission, result ? true : false);
|
||||
SDL_free(info->permission);
|
||||
SDL_free(info);
|
||||
@@ -3200,7 +3200,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePermissionResult)(
|
||||
prev = info;
|
||||
}
|
||||
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
SDL_UnlockMutex(SDL_event_lock);
|
||||
}
|
||||
|
||||
bool SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata)
|
||||
@@ -3228,10 +3228,10 @@ bool SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPerm
|
||||
info->callback = cb;
|
||||
info->userdata = userdata;
|
||||
|
||||
SDL_LockMutex(Android_ActivityMutex);
|
||||
SDL_LockMutex(SDL_event_lock);
|
||||
info->next = pending_permissions.next;
|
||||
pending_permissions.next = info;
|
||||
SDL_UnlockMutex(Android_ActivityMutex);
|
||||
SDL_UnlockMutex(SDL_event_lock);
|
||||
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
jstring jpermission = (*env)->NewStringUTF(env, permission);
|
||||
|
||||
Reference in New Issue
Block a user