Skip to content

Commit

Permalink
Fix a memory leak/resource cache issue, that keeps multimeshes in mem…
Browse files Browse the repository at this point in the history
…ory and spams 'instance_count > 0' errors when opening a scene
  • Loading branch information
dreadpon committed Apr 30, 2024
1 parent 83def9c commit 71bf2a2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
14 changes: 11 additions & 3 deletions addons/dreadpon.spatial_gardener/arborist/arborist.gd
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,22 @@ func _enter_tree():
# thread_instance_placement.start(Callable(self,"thread_update_LODs"))


func _notification(what):
match what:
NOTIFICATION_PREDELETE:
for octree_manager in octree_managers:
octree_manager.destroy()


func _exit_tree():
pass
# This is... weird
# Apparently I need to free any Resources that are left after closing a scene
# I'm not exactly sure why
# And it *might* be destructive to do so in editor
if Engine.is_editor_hint(): return
# for octree_manager in octree_managers:
# octree_manager.destroy()
#if Engine.is_editor_hint(): return
#for octree_manager in octree_managers:
#octree_manager.destroy()
# octree_managers = []
# mutex_placement.lock()
# exit_instance_placement = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ func set_is_leaf(val):


func destroy():
member_placeforms = []
parent = null
MMI_container = null
MMI = null
MMI_multimesh = null
shared_LOD_variants = []

for child in child_nodes:
child.destroy()
child_nodes = []
Expand Down
1 change: 1 addition & 0 deletions testing/tests/gardener_tests/test_gardener_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func _enter_tree():

func _exit_tree():
FunLib.free_children(self)
gardener = null


func dpon_testing_set_editor_selection(val):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ func save_gardener():
var packed_scene = PackedScene.new()
packed_scene.pack(gardener)
FunLib.save_res(packed_scene, greenhouse_path, "gardener.tscn")
remove_child(gardener)
editor_selection.clear()
remove_child(gardener)
gardener.free()
gardener = null


func load_gardener():
Expand Down

0 comments on commit 71bf2a2

Please sign in to comment.