Skip to content

Commit adbbf1a

Browse files
committed
Fix object_set_instance being wrongly called for built-in wrapped classes
1 parent f58a2f2 commit adbbf1a

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

include/godot_cpp/classes/wrapped.hpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Wrapped {
4545
friend void postinitialize_handler(Wrapped *);
4646

4747
protected:
48-
virtual const char *_get_class() const = 0; // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
48+
virtual const char *_get_extension_class() const; // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
4949
virtual const GDNativeInstanceBindingCallbacks *_get_bindings_callbacks() const = 0;
5050

5151
void _postinitialize();
@@ -60,26 +60,13 @@ class Wrapped {
6060

6161
} // namespace godot
6262

63-
#ifdef DEBUG_ENABLED
64-
#define CHECK_CLASS_CONSTRUCTOR(m_constructor, m_class) \
65-
if (unlikely(!m_constructor)) { \
66-
ERR_PRINT_ONCE("Constructor for class " #m_class "not found. Likely wasn't registered in ClassDB."); \
67-
return nullptr; \
68-
} else \
69-
((void)0)
70-
#else
71-
#define CHECK_CLASS_CONSTRUCTOR(m_constructor, m_class)
72-
#endif
73-
7463
#define GDCLASS(m_class, m_inherits) \
7564
private: \
7665
void operator=(const m_class &p_rval) {} \
7766
friend class ClassDB; \
7867
\
79-
using SelfType = m_class; \
80-
\
8168
protected: \
82-
virtual const char *_get_class() const override { \
69+
virtual const char *_get_extension_class() const override { \
8370
return get_class_static(); \
8471
} \
8572
\
@@ -151,10 +138,6 @@ private:
151138
void operator=(const m_class &p_rval) {} \
152139
\
153140
protected: \
154-
virtual const char *_get_class() const override { \
155-
return get_class_static(); \
156-
} \
157-
\
158141
virtual const GDNativeInstanceBindingCallbacks *_get_bindings_callbacks() const override { \
159142
return &___binding_callbacks; \
160143
} \

src/classes/wrapped.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@
3636

3737
namespace godot {
3838

39+
const char *Wrapped::_get_extension_class() const {
40+
return nullptr;
41+
}
42+
3943
void Wrapped::_postinitialize() {
40-
godot::internal::gdn_interface->object_set_instance(_owner, _get_class(), this);
44+
const char *extension_class = _get_extension_class();
45+
if (extension_class) {
46+
godot::internal::gdn_interface->object_set_instance(_owner, extension_class, this);
47+
}
4148
godot::internal::gdn_interface->object_set_instance_binding(_owner, godot::internal::token, this, _get_bindings_callbacks());
4249
}
4350

0 commit comments

Comments
 (0)