From 4cf5a18721311e1282a43f32178fb632560d042b Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 28 Dec 2023 14:41:58 +0100 Subject: [PATCH] Fix another potential crash related to debugger not being active --- bt/bt_state.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bt/bt_state.cpp b/bt/bt_state.cpp index 880e713..e185909 100644 --- a/bt/bt_state.cpp +++ b/bt/bt_state.cpp @@ -15,6 +15,7 @@ #include "modules/limboai/hsm/limbo_state.h" #include "modules/limboai/util/limbo_string_names.h" +#include "core/debugger/engine_debugger.h" #include "core/error/error_macros.h" #include "core/object/class_db.h" #include "core/variant/variant.h" @@ -24,7 +25,9 @@ void BTState::_setup() { tree_instance = behavior_tree->instantiate(get_agent(), get_blackboard()); #ifdef DEBUG_ENABLED - LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path()); + if (tree_instance.is_valid() && EngineDebugger::is_active()) { + LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path()); + } #endif } @@ -48,12 +51,12 @@ void BTState::_update(double p_delta) { void BTState::_notification(int p_notification) { switch (p_notification) { case NOTIFICATION_ENTER_TREE: { - if (tree_instance.is_valid()) { + if (tree_instance.is_valid() && EngineDebugger::is_active()) { LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path()); } } break; case NOTIFICATION_EXIT_TREE: { - if (tree_instance.is_valid()) { + if (tree_instance.is_valid() && EngineDebugger::is_active()) { LimboDebugger::get_singleton()->unregister_bt_instance(tree_instance, get_path()); } } break;