Skip to content

Commit ecba986

Browse files
dbnicholsonwnbaum
authored andcommitted
Fix inspector plugin leak
Handling the inspector plugin as a static variable of the BlockCode class means it can never be removed from inspector since we never know when all BlockCode instances have been destroyed. That means it had to be leaked as shown in the verbose Godot output: WARNING: ObjectDB instances leaked at exit (run with --verbose for details). at: cleanup (core/object/object.cpp:2209) Leaked instance: EditorPlugin:1833129019089 - Node name: Instead, add it once from the plugin entry point. That means it can also be removed when the plugin exits rather than being leaked. This follows the pattern documented in the Inspector Plugin tutorial[1]. 1. https://docs.godotengine.org/en/stable/tutorials/plugins/editor/inspector_plugins.html.
1 parent 8c472b9 commit ecba986

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

addons/block_code/block_code_node/block_code.gd

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class_name BlockCode
44
extends Node
55

66
@export var block_script: BlockScriptData = null
7-
static var plugin
87

98

109
func _ready():
@@ -31,10 +30,6 @@ func _enter_tree():
3130
new_bsd.generated_script = new_bsd.generated_script.replace("INHERIT_DEFAULT", new_bsd.script_inherits)
3231
block_script = new_bsd
3332

34-
if plugin == null:
35-
plugin = ClassDB.instantiate("EditorPlugin")
36-
plugin.add_inspector_plugin(load("res://addons/block_code/inspector_plugin/block_script_inspector.gd").new())
37-
3833

3934
func _update_parent_script():
4035
if Engine.is_editor_hint():

addons/block_code/block_code_plugin.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const MainPanel := preload("res://addons/block_code/ui/main_panel.tscn")
66
static var main_panel: MainPanel
77
static var block_code_button: Button
88

9+
const BlockInspectorPlugin := preload("res://addons/block_code/inspector_plugin/block_script_inspector.gd")
10+
var block_inspector_plugin: BlockInspectorPlugin
11+
912
var editor_inspector: EditorInspector
1013
var editor_selection: EditorSelection
1114

@@ -52,6 +55,8 @@ func _enter_tree():
5255
main_panel = MainPanel.instantiate()
5356
main_panel.undo_redo = get_undo_redo()
5457
block_code_button = add_control_to_bottom_panel(main_panel, _get_plugin_name())
58+
block_inspector_plugin = BlockInspectorPlugin.new()
59+
add_inspector_plugin(block_inspector_plugin)
5560

5661
# Remove unwanted class nodes from create node
5762
old_feature_profile = EditorInterface.get_current_feature_profile()
@@ -71,6 +76,8 @@ func _enter_tree():
7176

7277

7378
func _exit_tree():
79+
remove_inspector_plugin(block_inspector_plugin)
80+
7481
if block_code_button:
7582
remove_control_from_bottom_panel(main_panel)
7683
block_code_button = null

0 commit comments

Comments
 (0)