Skip to content

Commit f50f127

Browse files
authored
Merge pull request #240 from winnerspiros/copilot/fix-apk-crash-issue-one-more-time
Marshal SetSustainedPerformanceMode onto the Android UI thread
2 parents dab4d2a + ae71430 commit f50f127

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

osu.Android/OsuGameAndroid.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,29 @@ protected override void LoadComplete()
267267

268268
// Always enable sustained performance mode for consistent frame delivery.
269269
// This prevents thermal throttling from causing sudden FPS drops.
270-
try { gameActivity.Window?.SetSustainedPerformanceMode(true); }
271-
catch { }
270+
//
271+
// This MUST run on the Android UI thread: SetSustainedPerformanceMode mutates
272+
// window state through ViewRootImpl, which enforces single-threaded access via
273+
// checkThread() and throws CalledFromWrongThreadException otherwise. On some
274+
// OEM frameworks (observed on Samsung One UI / Adreno) that exception unwinds
275+
// through setPrivateFlags after the underlying Surface has already been
276+
// partially reconfigured, invalidating the active VkSurfaceKHR and crashing the
277+
// Vulkan driver inside vkCmdBeginRendering on the next frame.
278+
try
279+
{
280+
gameActivity.RunOnUiThread(() =>
281+
{
282+
try { gameActivity.Window?.SetSustainedPerformanceMode(true); }
283+
catch (Exception e)
284+
{
285+
Debug.WriteLine($"[osu!] Failed to enable sustained performance mode: {e.Message}");
286+
}
287+
});
288+
}
289+
catch (Exception e)
290+
{
291+
Debug.WriteLine($"[osu!] Failed to dispatch sustained performance mode toggle to UI thread: {e.Message}");
292+
}
272293

273294
base.LoadComplete();
274295

0 commit comments

Comments
 (0)