From 4979305b2d59188e97efd03e4e49e90aacb32485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 25 Mar 2024 11:34:29 +0100 Subject: [PATCH] Ensure `TryDisableCustomRulesetsCausing()` never actually crashes itself --- osu.Game/Rulesets/RealmRulesetStore.cs | 31 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/osu.Game/Rulesets/RealmRulesetStore.cs b/osu.Game/Rulesets/RealmRulesetStore.cs index 36eae7af2c..2455a9a73f 100644 --- a/osu.Game/Rulesets/RealmRulesetStore.cs +++ b/osu.Game/Rulesets/RealmRulesetStore.cs @@ -164,26 +164,33 @@ namespace osu.Game.Rulesets internal void TryDisableCustomRulesetsCausing(Exception exception) { - var stackTrace = new StackTrace(exception); - - foreach (var frame in stackTrace.GetFrames()) + try { - var declaringAssembly = frame.GetMethod()?.DeclaringType?.Assembly; - if (declaringAssembly == null) - continue; + var stackTrace = new StackTrace(exception); - if (UserRulesetAssemblies.Contains(declaringAssembly)) + foreach (var frame in stackTrace.GetFrames()) { - string sourceLocation = declaringAssembly.Location; - string destinationLocation = Path.ChangeExtension(sourceLocation, @".dll.broken"); + var declaringAssembly = frame.GetMethod()?.DeclaringType?.Assembly; + if (declaringAssembly == null) + continue; - if (File.Exists(sourceLocation)) + if (UserRulesetAssemblies.Contains(declaringAssembly)) { - Logger.Log($"Unhandled exception traced back to custom ruleset {Path.GetFileNameWithoutExtension(sourceLocation)}. Marking as broken."); - File.Move(sourceLocation, destinationLocation); + string sourceLocation = declaringAssembly.Location; + string destinationLocation = Path.ChangeExtension(sourceLocation, @".dll.broken"); + + if (File.Exists(sourceLocation)) + { + Logger.Log($"Unhandled exception traced back to custom ruleset {Path.GetFileNameWithoutExtension(sourceLocation)}. Marking as broken."); + File.Move(sourceLocation, destinationLocation); + } } } } + catch (Exception ex) + { + Logger.Log($"Attempt to trace back crash to custom ruleset failed: {ex}"); + } } } }