fix(android): add JNI activation constructor to OsuGameActivity to fix startup crash - #324
Merged
Merged
Conversation
…to fix JNI activation crash Agent-Logs-Url: https://github.com/winnerspiros/osu/sessions/0a7096f4-e29c-4d75-a84b-5d7de0b80ff1 Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
winnerspiros
May 9, 2026 11:22
View session
There was a problem hiding this comment.
Pull request overview
Fixes an Android startup crash during Android-initiated Activity recreation (e.g., process death / back-stack restore) by adding the required JNI activation constructor directly to OsuGameActivity, ensuring .NET Android’s TypeManager.Activate can instantiate the concrete managed type.
Changes:
- Added
OsuGameActivity(IntPtr, JniHandleOwnership)constructor forwarding to the base constructor. - Expanded inline comments to document why the constructor is required on the concrete type and how it relates to existing linker/trimming guards.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
TypeManager.Activatein .NET Android resolves(IntPtr, JniHandleOwnership)viaGetConstructoron the concrete managed type — it does not walk the inheritance chain.OsuGameActivitynever defined this constructor, so activation always fell through and threwNotSupportedExceptionon any Android-initiated instantiation (process death + recreation, back-stack restore).The existing guards (
preserve="all"forosu.Android,AndroidLinkSkipforosu.Framework.Android/SDL3-CS,[DynamicDependency]attributes) all protect the base class constructors from trimming but do nothing for a constructor that was never defined on the concrete type in the first place.Changes
osu.Android/OsuGameActivity.cs— adds the required JNI activation constructor directly onOsuGameActivity:This is the standard .NET Android pattern: every concrete
Java.Lang.Objectsubclass instantiatable by the Android runtime must declare this constructor explicitly on the concrete type, not just inherit it.