From 18e52d1a25d012f42e9e0f294db2960a0f843053 Mon Sep 17 00:00:00 2001 From: stevenh Date: Tue, 28 Feb 2012 10:58:40 +0000 Subject: [PATCH] Added protection against downstream exceptions when saving the world --- TShockAPI/SaveManager.cs | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/TShockAPI/SaveManager.cs b/TShockAPI/SaveManager.cs index dca8628e..f411a2ef 100644 --- a/TShockAPI/SaveManager.cs +++ b/TShockAPI/SaveManager.cs @@ -31,7 +31,17 @@ namespace TShockAPI /// public void OnSaveWorld(bool resettime = false, HandledEventArgs e = null) { - TShock.Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red); + // Protect against internal errors causing save failures + // These can be caused by an unexpected error such as a bad or out of date plugin + try + { + TShock.Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red); + } + catch (Exception ex) + { + Log.Error("World saved notification failed"); + Log.Error(ex.ToString()); + } } /// @@ -88,15 +98,25 @@ namespace TShockAPI return; else { - if (task.direct) + // Ensure that save handler errors don't bubble up and cause a recursive call + // These can be caused by an unexpected error such as a bad or out of date plugin + try { - OnSaveWorld(); - WorldGen.realsaveWorld(task.resetTime); + if (task.direct) + { + OnSaveWorld(); + WorldGen.realsaveWorld(task.resetTime); + } + else + WorldGen.saveWorld(task.resetTime); + TShock.Utils.Broadcast("World saved.", Color.Yellow); + Log.Info(string.Format("World saved at ({0})", Main.worldPathName)); + } + catch (Exception e) + { + Log.Error("World saved failed"); + Log.Error(e.ToString()); } - else - WorldGen.saveWorld(task.resetTime); - TShock.Utils.Broadcast("World saved.", Color.Yellow); - Log.Info(string.Format("World saved at ({0})", Main.worldPathName)); } } }