Skip to content

Commit 9d81331

Browse files
committed
Add protections against registering classes that didn't use GDCLASS()
(cherry picked from commit a61cdc8)
1 parent ef8a499 commit 9d81331

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/godot_cpp/classes/wrapped.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ protected:
170170
} \
171171
\
172172
public: \
173+
typedef m_class self_type; \
174+
\
173175
static void initialize_class() { \
174176
static bool initialized = false; \
175177
if (initialized) { \
@@ -372,6 +374,8 @@ protected:
372374
} \
373375
\
374376
public: \
377+
typedef m_class self_type; \
378+
\
375379
static void initialize_class() {} \
376380
\
377381
static ::godot::StringName &get_class_static() { \
@@ -381,6 +385,17 @@ public:
381385
\
382386
static ::godot::StringName &get_parent_class_static() { \
383387
return m_inherits::get_class_static(); \
388+
} \
389+
\
390+
static GDExtensionObjectPtr create(void *data) { \
391+
return nullptr; \
392+
} \
393+
\
394+
static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) { \
395+
return nullptr; \
396+
} \
397+
\
398+
static void free(void *data, GDExtensionClassInstancePtr ptr) { \
384399
} \
385400
\
386401
static void *_gde_binding_create_callback(void *p_token, void *p_instance) { \

include/godot_cpp/core/class_db.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class ClassDB {
173173

174174
template <class T, bool is_abstract>
175175
void ClassDB::_register_class(bool p_virtual) {
176+
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
176177
instance_binding_callbacks[T::get_class_static()] = &T::_gde_binding_callbacks;
177178

178179
// Register this class within our plugin

0 commit comments

Comments
 (0)