Skip to content

Commit fd1ac1c

Browse files
committed
Fix BBNode::get_value() crash with a freed object in GDExtension
It may be a bug in GDExtension. I optimized the code, and, as a workaround, removed casting to Object* from Variant. This fixed the issue. The same code worked well using module. (cherry picked from commit 689c8fa)
1 parent 644c589 commit fd1ac1c

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

blackboard/bb_param/bb_node.cpp

+4-16
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111

1212
#include "bb_node.h"
1313

14-
#ifdef LIMBOAI_MODULE
15-
#include "core/error/error_macros.h"
16-
#include "scene/main/node.h"
17-
#endif // LIMBOAI_MODULE
18-
19-
#ifdef LIMBOAI_GDEXTENSION
20-
#include <godot_cpp/classes/node.hpp>
21-
#endif // LIMBOAI_GDEXTENSION
22-
2314
Variant BBNode::get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboard, const Variant &p_default) {
2415
ERR_FAIL_NULL_V_MSG(p_scene_root, Variant(), "BBNode: get_value() failed - scene_root is null.");
2516
ERR_FAIL_NULL_V_MSG(p_blackboard, Variant(), "BBNode: get_value() failed - blackboard is null.");
@@ -33,13 +24,10 @@ Variant BBNode::get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboar
3324

3425
if (val.get_type() == Variant::NODE_PATH) {
3526
return p_scene_root->get_node_or_null(val);
27+
} else if (val.get_type() == Variant::OBJECT || val.get_type() == Variant::NIL) {
28+
return val;
3629
} else {
37-
Object *obj = val;
38-
if (unlikely(obj == nullptr && val.get_type() != Variant::NIL)) {
39-
WARN_PRINT("BBNode: Unexpected variant type of a blackboard variable.");
40-
return p_default;
41-
} else {
42-
return obj;
43-
}
30+
WARN_PRINT("BBNode: Unexpected variant type: " + Variant::get_type_name(val.get_type()) + ". Returning default value.");
31+
return p_default;
4432
}
4533
}

0 commit comments

Comments
 (0)