Fix crash when freeing agent with performance monitoring enabled
This commit is contained in:
parent
db73133f1b
commit
7eaebc4e7c
|
@ -153,21 +153,31 @@ void BTPlayer::restart() {
|
||||||
void BTPlayer::_set_monitor_performance(bool p_monitor_performance) {
|
void BTPlayer::_set_monitor_performance(bool p_monitor_performance) {
|
||||||
monitor_performance = p_monitor_performance;
|
monitor_performance = p_monitor_performance;
|
||||||
|
|
||||||
if (!get_owner()) {
|
if (!get_owner() && monitor_performance) {
|
||||||
|
// Don't add custom monitor if not in scene.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Performance *perf = Performance::get_singleton();
|
|
||||||
if (monitor_performance) {
|
if (monitor_performance) {
|
||||||
if (monitor_id == StringName()) {
|
_add_custom_monitor();
|
||||||
monitor_id = vformat("limboai/update_ms|%s_%s_%s", get_owner()->get_name(), get_name(),
|
} else {
|
||||||
String(itos(get_instance_id())).md5_text().substr(0, 4));
|
_remove_custom_monitor();
|
||||||
}
|
}
|
||||||
if (!perf->has_custom_monitor(monitor_id)) {
|
}
|
||||||
PERFORMANCE_ADD_CUSTOM_MONITOR(monitor_id, callable_mp(this, &BTPlayer::_get_mean_update_time_msec));
|
|
||||||
}
|
void BTPlayer::_add_custom_monitor() {
|
||||||
} else if (monitor_id != StringName() && perf->has_custom_monitor(monitor_id)) {
|
if (monitor_id == StringName()) {
|
||||||
perf->remove_custom_monitor(monitor_id);
|
monitor_id = vformat("LimboAI/update_ms|%s_%s_%s", get_owner()->get_name(), get_name(),
|
||||||
|
String(itos(get_instance_id())).md5_text().substr(0, 4));
|
||||||
|
}
|
||||||
|
if (!Performance::get_singleton()->has_custom_monitor(monitor_id)) {
|
||||||
|
PERFORMANCE_ADD_CUSTOM_MONITOR(monitor_id, callable_mp(this, &BTPlayer::_get_mean_update_time_msec));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BTPlayer::_remove_custom_monitor() {
|
||||||
|
if (monitor_id != StringName() && Performance::get_singleton()->has_custom_monitor(monitor_id)) {
|
||||||
|
Performance::get_singleton()->remove_custom_monitor(monitor_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,9 +215,6 @@ void BTPlayer::_notification(int p_notification) {
|
||||||
_load_tree();
|
_load_tree();
|
||||||
}
|
}
|
||||||
set_active(active);
|
set_active(active);
|
||||||
#ifdef DEBUG_ENABLED
|
|
||||||
_set_monitor_performance(monitor_performance);
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
_update_blackboard_plan();
|
_update_blackboard_plan();
|
||||||
}
|
}
|
||||||
|
@ -217,6 +224,9 @@ void BTPlayer::_notification(int p_notification) {
|
||||||
if (tree_instance.is_valid() && IS_DEBUGGER_ACTIVE()) {
|
if (tree_instance.is_valid() && IS_DEBUGGER_ACTIVE()) {
|
||||||
LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path());
|
LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path());
|
||||||
}
|
}
|
||||||
|
if (monitor_performance) {
|
||||||
|
_add_custom_monitor();
|
||||||
|
}
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
|
@ -224,6 +234,9 @@ void BTPlayer::_notification(int p_notification) {
|
||||||
if (tree_instance.is_valid() && IS_DEBUGGER_ACTIVE()) {
|
if (tree_instance.is_valid() && IS_DEBUGGER_ACTIVE()) {
|
||||||
LimboDebugger::get_singleton()->unregister_bt_instance(tree_instance, get_path());
|
LimboDebugger::get_singleton()->unregister_bt_instance(tree_instance, get_path());
|
||||||
}
|
}
|
||||||
|
if (monitor_performance) {
|
||||||
|
_remove_custom_monitor();
|
||||||
|
}
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
|
|
||||||
if (Engine::get_singleton()->is_editor_hint()) {
|
if (Engine::get_singleton()->is_editor_hint()) {
|
||||||
|
@ -231,7 +244,6 @@ void BTPlayer::_notification(int p_notification) {
|
||||||
behavior_tree->disconnect(LW_NAME(plan_changed), callable_mp(this, &BTPlayer::_update_blackboard_plan));
|
behavior_tree->disconnect(LW_NAME(plan_changed), callable_mp(this, &BTPlayer::_update_blackboard_plan));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,10 @@ private:
|
||||||
|
|
||||||
void _set_monitor_performance(bool p_monitor_performance);
|
void _set_monitor_performance(bool p_monitor_performance);
|
||||||
bool _get_monitor_performance() const { return monitor_performance; }
|
bool _get_monitor_performance() const { return monitor_performance; }
|
||||||
|
|
||||||
|
void _add_custom_monitor();
|
||||||
|
void _remove_custom_monitor();
|
||||||
|
|
||||||
double _get_mean_update_time_msec();
|
double _get_mean_update_time_msec();
|
||||||
|
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
|
|
Loading…
Reference in New Issue