Skip to content

Commit

Permalink
Android: add timeout when waiting the SDL thread to finish
Browse files Browse the repository at this point in the history
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
  • Loading branch information
1bsyl committed Jun 12, 2023
1 parent 125e742 commit 4e0f94e
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4e0f94e

Please sign in to comment.