From 4e0f94ea7d58d4a1aac624421d73110232df3efd Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Mon, 12 Jun 2023 11:45:46 +0200
Subject: [PATCH] Android: add timeout when waiting the SDL thread to finish
C SDLmain() thread might have started (mSDLThread.start() called)
while the SDL_Init() might not have been called yet,
and so the previous QUIT event will be discarded by SDL_Init() and app is running, not exiting.
This is reprocible by adding instrumentation code in the SDLActivity.
And hopefully, this could fix an ANR, where SDLActivity is in WAITING state (in thread.join()):
at java.lang.Thread.join (Thread.java:1519)
at org.libsdl.app.SDLActivity.onDestroy (SDLActivity.java)
while SDLThread seems to be running
---
.../app/src/main/java/org/libsdl/app/SDLActivity.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 24f10fb6b64b..629dabb16802 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -658,7 +658,11 @@ protected void onDestroy() {
// Wait for "SDLThread" thread to end
try {
- SDLActivity.mSDLThread.join();
+ // 500ms timeout, because:
+ // C SDLmain() thread might have started (mSDLThread.start() called)
+ // while the SDL_Init() might not have been called yet,
+ // and so the previous QUIT event will be discarded by SDL_Init() and app is running, not exiting.
+ SDLActivity.mSDLThread.join(500);
} catch(Exception e) {
Log.v(TAG, "Problem stopping SDLThread: " + e);
}