Skip to content

Commit f30d630

Browse files
Copilotwinnerspiros
andcommitted
Fix updateOrientation crash: dispatch to UI thread, add safe cast
The Android updateOrientation() set Activity.RequestedOrientation directly from the game update thread. On Samsung OneUI (S23 Ultra) and Android 13+, this throws CalledFromWrongThreadException because Android requires UI property changes on the UI thread. The iOS version correctly dispatched via InvokeOnMainThread but the Android version was missing the equivalent RunOnUiThread wrapper. Also replaced the unsafe direct cast (IOsuScreen)ScreenStack.CurrentScreen with a safe pattern check (is not IOsuScreen) to handle edge cases during initialization when CurrentScreen may not yet be an IOsuScreen. Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com> Agent-Logs-Url: https://github.com/winnerspiros/osu/sessions/502fe957-0685-4af6-b430-6862ca766056
1 parent da99329 commit f30d630

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

osu.Android/OsuGameAndroid.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,22 +245,28 @@ protected override void ScreenChanged(IOsuScreen? current, IOsuScreen? newScreen
245245

246246
private void updateOrientation()
247247
{
248-
var orientation = MobileUtils.GetOrientation(this, (IOsuScreen)ScreenStack.CurrentScreen, gameActivity.IsTablet);
249-
250-
switch (orientation)
248+
gameActivity.RunOnUiThread(() =>
251249
{
252-
case MobileUtils.Orientation.Locked:
253-
gameActivity.RequestedOrientation = ScreenOrientation.Locked;
254-
break;
250+
if (ScreenStack.CurrentScreen is not IOsuScreen currentScreen)
251+
return;
255252

256-
case MobileUtils.Orientation.Portrait:
257-
gameActivity.RequestedOrientation = ScreenOrientation.Portrait;
258-
break;
253+
var orientation = MobileUtils.GetOrientation(this, currentScreen, gameActivity.IsTablet);
259254

260-
case MobileUtils.Orientation.Default:
261-
gameActivity.RequestedOrientation = gameActivity.DefaultOrientation;
262-
break;
263-
}
255+
switch (orientation)
256+
{
257+
case MobileUtils.Orientation.Locked:
258+
gameActivity.RequestedOrientation = ScreenOrientation.Locked;
259+
break;
260+
261+
case MobileUtils.Orientation.Portrait:
262+
gameActivity.RequestedOrientation = ScreenOrientation.Portrait;
263+
break;
264+
265+
case MobileUtils.Orientation.Default:
266+
gameActivity.RequestedOrientation = gameActivity.DefaultOrientation;
267+
break;
268+
}
269+
});
264270
}
265271

266272
public override void SetHost(GameHost host)

0 commit comments

Comments
 (0)