Repository navigation
Fix casting crashing CastBay on Android 6: detach native threads on exit - #194
Merged
Merged
Conversation
UxPlay's threads attach to Java the first time they call back (currentEnv) and ended without detaching. Android 6's ART aborts the process when such a thread ends: "Native thread exited without calling DetachCurrentThread". Casting from an iPhone to a Xiaomi TV (Android 6.0.1) crashed CastBay three times in a row (report CB-4K36FJ; the TV's tombstones show the abort). Later Android versions only warn. A pthread key whose destructor detaches the thread is now set when a thread is attached, as ART's own warning suggests. tools/sim jnithread starts a native thread that attaches and exits. On the Xiaomi TV it reproduced the crash before this change, and the app survives it after; the emulator (Android 16) is unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes casting crashes on Android 6. Report CB-4K36FJ shows three restarts in a row on a Xiaomi TV (Android 6.0.1). The TV's tombstones show the cause: ART aborts with
Native thread exited without calling DetachCurrentThread.currentEnv()attached UxPlay threads to the JVM and never detached them. Android 7+ only warns about this, but Android 6 aborts the process. The fix registers a pthread key whose destructor callsDetachCurrentThread, as ART's warning suggests.Tests
tools/sim jnithread: a native thread attaches and exits.🤖 Generated with Claude Code