Skip to content

Commit 79f6b65

Browse files
Copilotwinnerspiros
andcommitted
Fix Android startup crash: guard native bridge type loading and protect Battery API
- Guard stopOboeBridge()/stopVulkanProbe() calls with nativeBridges != null check to prevent JIT compilation of [NoInlining] helpers during the initial false→false callback, which would otherwise trigger type loading of AndroidNativeBridgeManager (and potentially cascade to native P/Invoke types on Samsung devices). - Guard disposeNativeBridges() in Dispose with the same null check. - Wrap AndroidBatteryInfo.ChargeLevel and OnBattery in try-catch to prevent MAUI Essentials Battery API crashes on Samsung devices with aggressive battery optimization. Agent-Logs-Url: https://github.com/winnerspiros/osu/sessions/7246c167-0b69-48a2-9b47-0771fe6d1e63 Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
1 parent 4268e03 commit 79f6b65

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

osu.Android/OsuGameAndroid.cs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected override void LoadComplete()
139139
Debug.WriteLine($"[osu!] Audio offset auto-suggested: {suggested:F1}ms (hardware latency={latency:F1}ms)");
140140
});
141141
}
142-
else
142+
else if (nativeBridges != null)
143143
{
144144
stopOboeBridge();
145145
}
@@ -156,7 +156,7 @@ protected override void LoadComplete()
156156
{
157157
if (e.NewValue)
158158
startVulkanProbe();
159-
else
159+
else if (nativeBridges != null)
160160
stopVulkanProbe();
161161
}
162162
catch (Exception ex)
@@ -358,15 +358,42 @@ protected override void Dispose(bool isDisposing)
358358
}
359359
finally
360360
{
361-
disposeNativeBridges();
361+
if (nativeBridges != null)
362+
disposeNativeBridges();
362363
}
363364
}
364365

365366
private class AndroidBatteryInfo : BatteryInfo
366367
{
367-
public override double? ChargeLevel => Battery.ChargeLevel;
368+
public override double? ChargeLevel
369+
{
370+
get
371+
{
372+
try
373+
{
374+
return Battery.ChargeLevel;
375+
}
376+
catch
377+
{
378+
return null;
379+
}
380+
}
381+
}
368382

369-
public override bool OnBattery => Battery.PowerSource == BatteryPowerSource.Battery;
383+
public override bool OnBattery
384+
{
385+
get
386+
{
387+
try
388+
{
389+
return Battery.PowerSource == BatteryPowerSource.Battery;
390+
}
391+
catch
392+
{
393+
return false;
394+
}
395+
}
396+
}
370397
}
371398
}
372399
}

0 commit comments

Comments
 (0)