Skip to content

ANR when game loses focus (accessibility overlay, chat bubbles, etc.) due to gameThread.join() on UI thread #215

@ChillFrank

Description

@ChillFrank

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:

  1. Game thread shutdown blocking the UI thread

    BouncyActivity.pauseGame() calls FieldDriver.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 the running flag and exits naturally, so calling join() on the UI thread is unnecessary and unsafe.

  2. 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 from FieldDriver.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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions