From 9cddaab4d1811b367c9616d35e28a8c428cf3b3f Mon Sep 17 00:00:00 2001 From: lonesurvivor Date: Wed, 25 Jan 2017 20:52:44 +0100 Subject: [PATCH] When overlappinng Area2Ds are removed with remove_child(), _enter_tree and _exit_tree signals are now properly disconnected upon removal --- scene/2d/area_2d.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index a72e1164b44..96c5bea1378 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -357,6 +357,10 @@ void Area2D::_clear_monitoring() { Object *obj = ObjectDB::get_instance(E->key()); Node *node = obj ? obj->cast_to() : NULL; ERR_CONTINUE(!node); + + node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree); + if (!E->get().in_tree) continue; @@ -366,9 +370,6 @@ void Area2D::_clear_monitoring() { } emit_signal(SceneStringNames::get_singleton()->body_exited,obj); - - node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree); } } @@ -388,6 +389,9 @@ void Area2D::_clear_monitoring() { continue; //ERR_CONTINUE(!node); + node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree); + if (!E->get().in_tree) continue; @@ -397,9 +401,6 @@ void Area2D::_clear_monitoring() { } emit_signal(SceneStringNames::get_singleton()->area_exited,obj); - - node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree); } }