diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 830d314245d..38ad6886b1f 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -78,6 +78,17 @@ bool SceneTreeTimer::is_pause_mode_process() { return process_pause; } +void SceneTreeTimer::release_connections() { + + List connections; + get_all_signal_connections(&connections); + + for (List::Element *E = connections.front(); E; E = E->next()) { + Connection const &connection = E->get(); + disconnect(connection.signal, connection.target, connection.method); + } +} + SceneTreeTimer::SceneTreeTimer() { time_left = 0; process_pause = true; @@ -611,6 +622,12 @@ void SceneTree::finish() { memdelete(root); //delete root root = NULL; } + + // cleanup timers + for (List >::Element *E = timers.front(); E; E = E->next()) { + E->get()->release_connections(); + } + timers.clear(); } void SceneTree::quit() { diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index d387886d61c..ef847ebb5b7 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -61,6 +61,8 @@ public: void set_pause_mode_process(bool p_pause_mode_process); bool is_pause_mode_process(); + void release_connections(); + SceneTreeTimer(); };