From 5a76f3ebe5a4f165ca795df0f1f7eaf0c115de8f Mon Sep 17 00:00:00 2001 From: goat Date: Wed, 21 Jun 2023 21:42:00 +0200 Subject: [PATCH] fix: don't use tables for the installer layout, more ImRaii conversion Apparently children inside tables is UB --- .../PluginInstaller/PluginInstallerWindow.cs | 61 ++++++++----------- .../PluginInstaller/ProfileManagerWidget.cs | 10 ++- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 1e62d4742..ba249e051 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -392,7 +392,8 @@ internal class PluginInstallerWindow : Window, IDisposable var windowSize = ImGui.GetWindowSize(); var titleHeight = ImGui.GetFontSize() + (ImGui.GetStyle().FramePadding.Y * 2); - if (ImGui.BeginChild("###installerLoadingFrame", new Vector2(-1, -1), false)) + using var loadingChild = ImRaii.Child("###installerLoadingFrame", new Vector2(-1, -1), false); + if (loadingChild) { ImGui.GetWindowDrawList().PushClipRectFullScreen(); ImGui.GetWindowDrawList().AddRectFilled( @@ -480,8 +481,6 @@ internal class PluginInstallerWindow : Window, IDisposable ImGuiHelpers.CenteredText("One of your plugins may be blocking the installer."); ImGui.PopStyleColor(); } - - ImGui.EndChild(); } } @@ -1110,47 +1109,41 @@ internal class PluginInstallerWindow : Window, IDisposable var useContentWidth = ImGui.GetContentRegionAvail().X; - using var categoriesChild = ImRaii.Child("InstallerCategories", new Vector2(useContentWidth, useContentHeight * ImGuiHelpers.GlobalScale)); - if (categoriesChild) + using var installerMainChild = ImRaii.Child("InstallerCategories", new Vector2(useContentWidth, useContentHeight * ImGuiHelpers.GlobalScale)); + if (installerMainChild) { using var style = ImRaii.PushStyle(ImGuiStyleVar.CellPadding, ImGuiHelpers.ScaledVector2(5, 0)); - using var table = ImRaii.Table( - "##InstallerCategoriesCont", - 2, - ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.Resizable | ImGuiTableFlags.BordersInnerV); - - if (table) + + try { - try + using (var categoriesChild = ImRaii.Child("InstallerCategoriesSelector", new Vector2(useMenuWidth * ImGuiHelpers.GlobalScale, -1), false)) { - ImGui.TableSetupColumn("##InstallerCategoriesSelector", ImGuiTableColumnFlags.WidthFixed, useMenuWidth * ImGuiHelpers.GlobalScale); - ImGui.TableSetupColumn("##InstallerCategoriesBody", ImGuiTableColumnFlags.WidthStretch); - ImGui.TableNextRow(); - - ImGui.TableNextColumn(); - this.DrawPluginCategorySelectors(); - - ImGui.TableNextColumn(); - - using var scrollingChild = - ImRaii.Child("ScrollingPlugins", new Vector2(-1, 0), false, ImGuiWindowFlags.NoBackground); - if (scrollingChild) + if (categoriesChild) { - try - { - this.DrawPluginCategoryContent(); - } - catch (Exception ex) - { - Log.Error(ex, "Could not draw category content"); - } + this.DrawPluginCategorySelectors(); } } - catch (Exception ex) + + ImGui.SameLine(); + + using var scrollingChild = + ImRaii.Child("ScrollingPlugins", new Vector2(-1, -1), false, ImGuiWindowFlags.NoBackground); + if (scrollingChild) { - Log.Error(ex, "Could not draw plugin categories"); + try + { + this.DrawPluginCategoryContent(); + } + catch (Exception ex) + { + Log.Error(ex, "Could not draw category content"); + } } } + catch (Exception ex) + { + Log.Error(ex, "Could not draw plugin categories"); + } } } diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs index 8ec6be867..ca3ca34b0 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs @@ -107,7 +107,8 @@ internal class ProfileManagerWidget var windowSize = ImGui.GetWindowSize(); - if (ImGui.BeginChild("###profileChooserScrolling")) + using var profileChooserChild = ImRaii.Child("###profileChooserScrolling"); + if (profileChooserChild) { Guid? toCloneGuid = null; @@ -180,8 +181,6 @@ internal class ProfileManagerWidget ImGuiHelpers.CenteredText(Locs.AddProfileHint); ImGui.PopStyleColor(); } - - ImGui.EndChild(); } } @@ -325,7 +324,8 @@ internal class ProfileManagerWidget ImGui.Separator(); var wantPluginAddPopup = false; - if (ImGui.BeginChild("###profileEditorPluginList")) + using var pluginListChild = ImRaii.Child("###profileEditorPluginList"); + if (pluginListChild) { var pluginLineHeight = 32 * ImGuiHelpers.GlobalScale; string? wantRemovePluginInternalName = null; @@ -439,8 +439,6 @@ internal class ProfileManagerWidget ImGui.TextUnformatted(addPluginsText); ImGuiHelpers.ScaledDummy(10); - - ImGui.EndChild(); } if (wantPluginAddPopup)