Skip to content

Commit 0c82797

Browse files
fix: add (IntPtr, JniHandleOwnership) constructor to OsuGameActivity 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>
1 parent b6ea72e commit 0c82797

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

osu.Android/OsuGameActivity.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ protected override osu.Framework.Game CreateGame()
9898
// The explicit SDL3-CS attribute roots SDLActivity(IntPtr, JniHandleOwnership) — the actual
9999
// overload TypeManager.Activate calls — which has NO managed call-graph path and would
100100
// otherwise be silently trimmed even if the parameterless constructor chain is preserved.
101+
// See also the OsuGameActivity(IntPtr, JniHandleOwnership) constructor below, which is the
102+
// direct fix for the v2026.509.229 crash: TypeManager.Activate needs this on the concrete type.
101103
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors,
102104
"osu.Framework.Android.AndroidGameActivity", "osu.Framework.Android")]
103105
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors,
@@ -107,6 +109,19 @@ public OsuGameActivity()
107109
game = new OsuGameAndroid(this);
108110
}
109111

112+
// Required JNI activation constructor. TypeManager.Activate performs a reflection
113+
// lookup for (IntPtr, JniHandleOwnership) on the *concrete* managed type when Android
114+
// re-instantiates this Activity from a JNI handle (process death/recreation, back-stack
115+
// restore). Inheriting this constructor from AndroidGameActivity/SDLActivity is not
116+
// sufficient — .NET Android's TypeManager resolves it via GetConstructor on the concrete
117+
// type; if the method is absent there the lookup falls through and Activate throws
118+
// NotSupportedException ("Could not activate JNI Handle ... as managed type
119+
// 'osu.Android.OsuGameActivity'"), which is the crash seen in v2026.509.229.
120+
protected OsuGameActivity(IntPtr javaReference, JniHandleOwnership transfer)
121+
: base(javaReference, transfer)
122+
{
123+
}
124+
110125
protected override void OnCreate(Bundle? savedInstanceState)
111126
{
112127
// NOTE: do NOT assign RequestedOrientation here. The `[Activity]` attribute on this

0 commit comments

Comments
 (0)