From a25b61fc0dff31be9d4392a2a36421116fdc5799 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Mon, 15 Sep 2014 20:59:57 +0100 Subject: [PATCH] Fixed memory leak and null exception errors --- Assets/Fungus/Dialog/Editor/ChooseEditor.cs | 6 ++---- Assets/Fungus/Dialog/Editor/SayEditor.cs | 6 ++---- Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs | 1 + Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs | 5 +++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Assets/Fungus/Dialog/Editor/ChooseEditor.cs b/Assets/Fungus/Dialog/Editor/ChooseEditor.cs index ee8e6d8a..8e2aec44 100644 --- a/Assets/Fungus/Dialog/Editor/ChooseEditor.cs +++ b/Assets/Fungus/Dialog/Editor/ChooseEditor.cs @@ -58,10 +58,8 @@ namespace Fungus float aspect = (float)characterTexture.width / (float)characterTexture.height; Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(50), GUILayout.ExpandWidth(false)); CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor; - if (characterEditor != null) - { - characterEditor.DrawPreview(previewRect, characterTexture); - } + characterEditor.DrawPreview(previewRect, characterTexture); + DestroyImmediate(characterEditor); } EditorGUILayout.EndHorizontal(); diff --git a/Assets/Fungus/Dialog/Editor/SayEditor.cs b/Assets/Fungus/Dialog/Editor/SayEditor.cs index 8aa7e818..81228433 100644 --- a/Assets/Fungus/Dialog/Editor/SayEditor.cs +++ b/Assets/Fungus/Dialog/Editor/SayEditor.cs @@ -75,10 +75,8 @@ namespace Fungus float aspect = (float)characterTexture.width / (float)characterTexture.height; Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(50), GUILayout.ExpandWidth(false)); CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor; - if (characterEditor != null) - { - characterEditor.DrawPreview(previewRect, characterTexture); - } + characterEditor.DrawPreview(previewRect, characterTexture); + DestroyImmediate(characterEditor); } EditorGUILayout.EndHorizontal(); diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 291025c1..8e41d077 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -89,6 +89,7 @@ namespace Fungus { CommandEditor commandEditor = Editor.CreateEditor(t.selectedCommand) as CommandEditor; commandEditor.DrawCommandInspectorGUI(); + DestroyImmediate(commandEditor); } EditorGUILayout.Separator(); diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs index aaaaf52a..5f761d2d 100755 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs @@ -269,8 +269,9 @@ namespace Fungus { EditorGUILayout.Separator(); - SequenceEditor editor = Editor.CreateEditor(fungusScript.selectedSequence) as SequenceEditor; - editor.DrawSequenceGUI(fungusScript); + SequenceEditor sequenceEditor = Editor.CreateEditor(fungusScript.selectedSequence) as SequenceEditor; + sequenceEditor.DrawSequenceGUI(fungusScript); + DestroyImmediate(sequenceEditor); GUILayout.FlexibleSpace(); }