summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2019-07-10 21:51:43 +0200
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2019-07-10 21:51:47 +0200
commit2a8294ff2409e3f0d5e4d7e39547a9b17942e0b3 (patch)
treed0406dbb2ca4fd07f553e46d5d1b47ab1b4bf6c4 /modules
parent8b778f62347e7aff48122aa3945f1373b3fae5d3 (diff)
Mono: Fix null dereference in EditorExportPlatformAndroid
We need to dispose the GodotSharpExport export plugin before the editor destroys EditorSettings. Otherwise, if the GC disposes it at a later time, EditorExportPlatformAndroid will be freed after EditorSettings already was, and its device polling thread will try to access the EditorSettings singleton, resulting in null dereferencing.
Diffstat (limited to 'modules')
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs20
1 files changed, 19 insertions, 1 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
index 955574d5fe..a8a507e855 100644
--- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
@@ -26,6 +26,8 @@ namespace GodotTools
private MonoDevelopInstance monoDevelopInstance;
private MonoDevelopInstance visualStudioForMacInstance;
+ private WeakReference<GodotSharpExport> exportPluginWeak;
+
public MonoBottomPanel MonoBottomPanel { get; private set; }
private bool CreateProjectSolution()
@@ -513,11 +515,27 @@ namespace GodotTools
});
// Export plugin
- AddExportPlugin(new GodotSharpExport());
+ var exportPlugin = new GodotSharpExport();
+ AddExportPlugin(exportPlugin);
+ exportPluginWeak = new WeakReference<GodotSharpExport>(exportPlugin);
GodotSharpBuilds.Initialize();
}
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+
+ if (exportPluginWeak.TryGetTarget(out var exportPlugin))
+ {
+ // We need to dispose our export plugin before the editor destroys EditorSettings.
+ // Otherwise, if the GC disposes it at a later time, EditorExportPlatformAndroid
+ // will be freed after EditorSettings already was, and its device polling thread
+ // will try to access the EditorSettings singleton, resulting in null dereferencing.
+ exportPlugin.Dispose();
+ }
+ }
+
public void OnBeforeSerialize()
{
}