Skip to content

Commit 101477c

Browse files
Copilotwinnerspiros
andcommitted
Fix Android startup crash: guard assembly loading, null-check host window, prevent division by zero
Agent-Logs-Url: https://github.com/winnerspiros/osu/sessions/2d6db8b8-e94e-4a7e-9e29-c6d7a9c9cbc9 Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
1 parent cd2c7d4 commit 101477c

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

osu.Android/OsuGameActivity.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,17 @@ protected override void OnCreate(Bundle? savedInstanceState)
117117
// Manually load them so that they can be loaded by RulesetStore.loadFromAppDomain.
118118
// REMEMBER to fully uninstall previous version every time when investigating this!
119119
// Don't forget osu.Game.Tests.Android too.
120-
Assembly.Load("osu.Game.Rulesets.Osu");
121-
Assembly.Load("osu.Game.Rulesets.Taiko");
122-
Assembly.Load("osu.Game.Rulesets.Catch");
123-
Assembly.Load("osu.Game.Rulesets.Mania");
120+
foreach (string asm in new[] { "osu.Game.Rulesets.Osu", "osu.Game.Rulesets.Taiko", "osu.Game.Rulesets.Catch", "osu.Game.Rulesets.Mania" })
121+
{
122+
try
123+
{
124+
Assembly.Load(asm);
125+
}
126+
catch (Exception e)
127+
{
128+
Debug.WriteLine($"[osu!] Failed to load ruleset assembly {asm}: {e.Message}");
129+
}
130+
}
124131
}
125132

126133
protected override void OnResume()

osu.Android/OsuGameAndroid.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public partial class OsuGameAndroid : OsuGame
2828

2929
private readonly PackageInfo? packageInfo;
3030

31-
public override Vector2 ScalingContainerTargetDrawSize => new Vector2(1024, 1024 * DrawHeight / DrawWidth);
31+
public override Vector2 ScalingContainerTargetDrawSize => DrawWidth > 0
32+
? new Vector2(1024, 1024 * DrawHeight / DrawWidth)
33+
: new Vector2(1024, 768);
3234

3335
private readonly Bindable<bool> performanceMode = new Bindable<bool>();
3436
private readonly Bindable<bool> lowLatencyAudio = new Bindable<bool>();
@@ -305,7 +307,9 @@ private void updateOrientation()
305307
public override void SetHost(GameHost host)
306308
{
307309
base.SetHost(host);
308-
host.Window.CursorState |= CursorState.Hidden;
310+
311+
if (host.Window != null)
312+
host.Window.CursorState |= CursorState.Hidden;
309313
}
310314

311315
protected override UpdateManager CreateUpdateManager() => new MobileUpdateNotifier();

0 commit comments

Comments
 (0)