From e3d6b91d8be9344c72dfaf3bfbf0d323a3d3a9f1 Mon Sep 17 00:00:00 2001 From: goat Date: Sat, 11 Apr 2020 15:40:14 +0200 Subject: [PATCH] feat: add error handling for plugins that throw while drawing --- Dalamud/Interface/UiBuilder.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Dalamud/Interface/UiBuilder.cs b/Dalamud/Interface/UiBuilder.cs index 5ad397845..c58364f42 100644 --- a/Dalamud/Interface/UiBuilder.cs +++ b/Dalamud/Interface/UiBuilder.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using ImGuiNET; using ImGuiScene; +using Serilog; namespace Dalamud.Interface { @@ -74,9 +75,33 @@ namespace Dalamud.Interface /// public EventHandler OnOpenConfigUi; + private bool hasErrorWindow; + private void OnDraw() { ImGui.PushID(this.namespaceName); - OnBuildUi?.Invoke(); + + if (this.hasErrorWindow && ImGui.Begin(string.Format("{0} Error", this.namespaceName), ref this.hasErrorWindow, + ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize)) { + ImGui.Text(string.Format("The plugin {0} ran into an error.\nContact the plugin developer for support.\n\nPlease try restarting your game.", this.namespaceName)); + ImGui.Spacing(); + + if (ImGui.Button("OK")) { + this.hasErrorWindow = false; + } + + ImGui.End(); + } + + try { + OnBuildUi?.Invoke(); + } catch (Exception ex) { + Log.Error("[{0}] UiBuilder OnBuildUi caught exception"); + OnBuildUi = null; + OnOpenConfigUi = null; + + this.hasErrorWindow = true; + } + ImGui.PopID(); } }