-
Notifications
You must be signed in to change notification settings - Fork 128
Description
The game can freeze and trigger an ANR (Application Not Responding) when the app loses window focus while a game is running. This happens during various overlay or system UI interactions, for example:
- Accessibility overlays
- Messenger/chat bubbles
- Certain system UI elements
- Pressing the Android accessibility button and tapping the “Pause” overlay (this was 100% reproducible and how I initially discovered the bug)
Earlier reports of the same or very similar behavior:
There are two separate UI-thread blocking issues that can lead to ANRs during focus changes:
-
Game thread shutdown blocking the UI thread
BouncyActivity.pauseGame()callsFieldDriver.stop()on the main UI thread.
FieldDriver.stop()calls:gameThread.join()If the game thread does not terminate quickly, this blocks input dispatching for >5 seconds and causes an ANR.
The game loop already checks therunningflag and exits naturally, so callingjoin()on the UI thread is unnecessary and unsafe. -
Rendering wait blocking the UI thread
During focus changes (especially with accessibility overlays), the UI thread can block inside:
GL20Renderer.doDraw() → renderLock.wait()If the GL thread does not render a frame (which can happen during overlays or focus loss), the UI thread waits indefinitely, resulting in another ANR. Pressing Resume while in this frozen state reliably triggers it.
Both issues were resolved by:
- Removing the blocking
gameThread.join()call fromFieldDriver.stop() - Ensuring
GL20Renderer.doDraw()never waits on the UI thread and adding a timeout when waiting off the UI thread
After applying these changes, I was no longer able to reproduce the ANR, even when repeatedly triggering accessibility overlays, focus changes, and resume actions.
I hope this helps, and thank you for maintaining the project!