diff --git a/File_Format_Library/GUI/BFRES/BfresEditor.cs b/File_Format_Library/GUI/BFRES/BfresEditor.cs index 1b208324..d35c9d3e 100644 --- a/File_Format_Library/GUI/BFRES/BfresEditor.cs +++ b/File_Format_Library/GUI/BFRES/BfresEditor.cs @@ -99,7 +99,7 @@ namespace FirstPlugin.Forms stTabControl2.myBackColor = FormThemes.BaseTheme.FormBackColor; //Always create an instance of the viewport unless opengl is disabled - if (viewport == null && Runtime.UseOpenGL) + if (viewport == null && Runtime.UseOpenGL || viewport.IsDisposed && Runtime.UseOpenGL) { viewport = new Viewport(ObjectEditor.GetDrawableContainers()); viewport.Dock = DockStyle.Fill; diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs index 050d51b6..8cb3b9a8 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs @@ -292,6 +292,9 @@ namespace Toolbox.Library.Forms var node = treeViewCustom1.SelectedNode; if (node != null) { + var result = MessageBox.Show("If you remove this file, any unsaved progress will be lost! Continue?", + "Remove Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); + if (node is IFileFormat) { ((IFileFormat)node).Unload(); @@ -299,6 +302,14 @@ namespace Toolbox.Library.Forms treeViewCustom1.Nodes.Remove(node); ResetEditor(); + + //Force garbage collection. + GC.Collect(); + + // Wait for all finalizers to complete before continuing. + GC.WaitForPendingFinalizers(); + + ((IUpdateForm)Runtime.MainForm).UpdateForm(); } } diff --git a/Switch_Toolbox_Library/Interfaces/IUpdateForm.cs b/Switch_Toolbox_Library/Interfaces/IUpdateForm.cs new file mode 100644 index 00000000..54452972 --- /dev/null +++ b/Switch_Toolbox_Library/Interfaces/IUpdateForm.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Toolbox.Library +{ + //A simple interface for updating a form + public interface IUpdateForm + { + void UpdateForm(); + } +} diff --git a/Switch_Toolbox_Library/Toolbox.Library.dll b/Switch_Toolbox_Library/Toolbox.Library.dll index f4734f23..e8747a47 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.dll and b/Switch_Toolbox_Library/Toolbox.Library.dll differ diff --git a/Switch_Toolbox_Library/Toolbox.Library.pdb b/Switch_Toolbox_Library/Toolbox.Library.pdb index c9a016b0..c12c5a6e 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.pdb and b/Switch_Toolbox_Library/Toolbox.Library.pdb differ diff --git a/Switch_Toolbox_Library/Toolbox_Library.csproj b/Switch_Toolbox_Library/Toolbox_Library.csproj index 395daac9..9ef25e6b 100644 --- a/Switch_Toolbox_Library/Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Toolbox_Library.csproj @@ -249,6 +249,7 @@ + diff --git a/Toolbox/MainForm.cs b/Toolbox/MainForm.cs index cd78b17c..f7d60e8c 100644 --- a/Toolbox/MainForm.cs +++ b/Toolbox/MainForm.cs @@ -20,7 +20,7 @@ using Toolbox.Library.Rendering; namespace Toolbox { - public partial class MainForm : Form, IMdiContainer + public partial class MainForm : Form, IMdiContainer, IUpdateForm { private static MainForm _instance; public static MainForm Instance { get { return _instance == null ? _instance = new MainForm() : _instance; } } @@ -55,6 +55,15 @@ namespace Toolbox LoadConfig(); } + public void UpdateForm() + { + if (ActiveMdiChild is ObjectEditor) + { + var activeFile = ((ObjectEditor)ActiveMdiChild).GetActiveFile(); + SetFormatSettings(activeFile); + } + } + public void Reload() { LoadConfig(); @@ -243,10 +252,8 @@ namespace Toolbox if (File.Exists(FileName)) SaveRecentFile(FileName); - object file = STFileLoader.OpenFileFormat(FileName); - if (file == null) //File might not be supported so return return;