Skip to content

Commit

Permalink
Added try catch clause in Update around StartLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
nhruo123 committed Jul 31, 2023
1 parent 1e16d6a commit 5cc7a9b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Celeste.Mod.mm/Patches/LevelLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private XmlDocument getModdedSpritesXml(string path) {

[MonoModIgnore] // We don't want to change anything about the method...
[PatchLoadingThreadAddEvent] // ... except for manually manipulating the method via MonoModRules
[PatchLoadingThreadAddSubHudRenderer]
[PatchLoadingThreadAddSubHudRenderer]
private extern void LoadingThread();

private void LoadingThread_Safe() {
Expand All @@ -214,14 +214,14 @@ private void LoadingThread_Safe() {
break;
}
}

string type = "";
if (e.TypeInStacktrace(typeof(SolidTiles))) {
type = "fg";
} else if (e.TypeInStacktrace(typeof(BackgroundTiles))) {
type = "bg";
}

patch_LevelEnter.ErrorMessage = Dialog.Get("postcard_badtileid")
.Replace("((type))", type).Replace("((id))", ex.ID.ToString()).Replace("((x))", ex.X.ToString())
.Replace("((y))", ex.Y.ToString()).Replace("((room))", room).Replace("((sid))", sid);
Expand All @@ -248,9 +248,16 @@ public override void Update() {
base_Update();
if (Loaded && !started) {
if (patch_LevelEnter.ErrorMessage == null) {
StartLevel();
}
else {
try {
StartLevel();
} catch (Exception e) {
string SID = session.Area.GetSID();
patch_LevelEnter.ErrorMessage = Dialog.Get("postcard_levelloadfailed").Replace("((sid))", SID);
Logger.Log(LogLevel.Warn, "LevelLoader", $"Failed Starting Level at room {session.Level} of {SID}");
e.LogDetailed();
LevelEnter.Go(session, false);
}
} else {
LevelEnter.Go(session, false); // We encountered an error, so display the error screen
}
}
Expand Down

0 comments on commit 5cc7a9b

Please sign in to comment.