Skip to content

Commit 20ca6f9

Browse files
committed
Revert "GameActivity PATCH: fix deadlocks in java callbacks after app destroyed"
This reverts commit 2a2f276.
1 parent 92c0051 commit 20ca6f9

File tree

1 file changed

+5
-58
lines changed

1 file changed

+5
-58
lines changed

android-activity/game-activity-csrc/game-activity/native_app_glue/android_native_app_glue.c

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,6 @@ static void android_app_set_window(struct android_app* android_app,
326326
ANativeWindow* window) {
327327
LOGV("android_app_set_window called");
328328
pthread_mutex_lock(&android_app->mutex);
329-
330-
// NB: we have to consider that the native thread could have already
331-
// (gracefully) exit (setting android_app->destroyed) and so we need
332-
// to be careful to avoid a deadlock waiting for a thread that's
333-
// already exit.
334-
if (android_app->destroyed) {
335-
pthread_mutex_unlock(&android_app->mutex);
336-
return;
337-
}
338329
if (android_app->pendingWindow != NULL) {
339330
android_app_write_cmd(android_app, APP_CMD_TERM_WINDOW);
340331
}
@@ -351,16 +342,9 @@ static void android_app_set_window(struct android_app* android_app,
351342
static void android_app_set_activity_state(struct android_app* android_app,
352343
int8_t cmd) {
353344
pthread_mutex_lock(&android_app->mutex);
354-
355-
// NB: we have to consider that the native thread could have already
356-
// (gracefully) exit (setting android_app->destroyed) and so we need
357-
// to be careful to avoid a deadlock waiting for a thread that's
358-
// already exit.
359-
if (!android_app->destroyed) {
360-
android_app_write_cmd(android_app, cmd);
361-
while (android_app->activityState != cmd) {
362-
pthread_cond_wait(&android_app->cond, &android_app->mutex);
363-
}
345+
android_app_write_cmd(android_app, cmd);
346+
while (android_app->activityState != cmd) {
347+
pthread_cond_wait(&android_app->cond, &android_app->mutex);
364348
}
365349
pthread_mutex_unlock(&android_app->mutex);
366350
}
@@ -369,14 +353,6 @@ static void android_app_free(struct android_app* android_app) {
369353
int input_buf_idx = 0;
370354

371355
pthread_mutex_lock(&android_app->mutex);
372-
373-
// It's possible that onDestroy is called after we have already 'destroyed'
374-
// the app (via `android_app_destroy` due to `android_main` returning.
375-
//
376-
// In this case `->destroyed` will already be set (so we won't deadlock in
377-
// the loop below) but we still need to close the messaging fds and finish
378-
// freeing the android_app
379-
380356
android_app_write_cmd(android_app, APP_CMD_DESTROY);
381357
while (!android_app->destroyed) {
382358
pthread_cond_wait(&android_app->cond, &android_app->mutex);
@@ -424,16 +400,6 @@ static void onSaveInstanceState(GameActivity* activity,
424400

425401
struct android_app* android_app = ToApp(activity);
426402
pthread_mutex_lock(&android_app->mutex);
427-
428-
// NB: we have to consider that the native thread could have already
429-
// (gracefully) exit (setting android_app->destroyed) and so we need
430-
// to be careful to avoid a deadlock waiting for a thread that's
431-
// already exit.
432-
if (android_app->destroyed) {
433-
pthread_mutex_unlock(&android_app->mutex);
434-
return;
435-
}
436-
437403
android_app->stateSaved = 0;
438404
android_app_write_cmd(android_app, APP_CMD_SAVE_STATE);
439405
while (!android_app->stateSaved) {
@@ -539,15 +505,6 @@ static bool onTouchEvent(GameActivity* activity,
539505
struct android_app* android_app = ToApp(activity);
540506
pthread_mutex_lock(&android_app->mutex);
541507

542-
// NB: we have to consider that the native thread could have already
543-
// (gracefully) exit (setting android_app->destroyed) and so we need
544-
// to be careful to avoid a deadlock waiting for a thread that's
545-
// already exit.
546-
if (android_app->destroyed) {
547-
pthread_mutex_unlock(&android_app->mutex);
548-
return false;
549-
}
550-
551508
if (android_app->motionEventFilter != NULL &&
552509
!android_app->motionEventFilter(event)) {
553510
pthread_mutex_unlock(&android_app->mutex);
@@ -625,15 +582,6 @@ static bool onKey(GameActivity* activity, const GameActivityKeyEvent* event) {
625582
struct android_app* android_app = ToApp(activity);
626583
pthread_mutex_lock(&android_app->mutex);
627584

628-
// NB: we have to consider that the native thread could have already
629-
// (gracefully) exit (setting android_app->destroyed) and so we need
630-
// to be careful to avoid a deadlock waiting for a thread that's
631-
// already exit.
632-
if (android_app->destroyed) {
633-
pthread_mutex_unlock(&android_app->mutex);
634-
return false;
635-
}
636-
637585
if (android_app->keyEventFilter != NULL &&
638586
!android_app->keyEventFilter(event)) {
639587
pthread_mutex_unlock(&android_app->mutex);
@@ -672,9 +620,8 @@ static void onTextInputEvent(GameActivity* activity,
672620
const GameTextInputState* state) {
673621
struct android_app* android_app = ToApp(activity);
674622
pthread_mutex_lock(&android_app->mutex);
675-
if (!android_app->destroyed) {
676-
android_app->textInputState = 1;
677-
}
623+
624+
android_app->textInputState = 1;
678625
pthread_mutex_unlock(&android_app->mutex);
679626
}
680627

0 commit comments

Comments
 (0)