Skip to content

Commit c82f2a3

Browse files
authored
Merge pull request #1279 from dsnopek/gdclass-protections
Add protections against registering classes that didn't use `GDCLASS()`
2 parents edb5229 + a61cdc8 commit c82f2a3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

include/godot_cpp/classes/wrapped.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ protected:
202202
} \
203203
\
204204
public: \
205+
typedef m_class self_type; \
206+
\
205207
static void initialize_class() { \
206208
static bool initialized = false; \
207209
if (initialized) { \
@@ -395,6 +397,10 @@ protected:
395397
return nullptr; \
396398
} \
397399
\
400+
static inline bool has_get_property_list() { \
401+
return false; \
402+
} \
403+
\
398404
static void (Wrapped::*_get_get_property_list())(List<PropertyInfo> * p_list) const { \
399405
return nullptr; \
400406
} \
@@ -416,6 +422,8 @@ protected:
416422
} \
417423
\
418424
public: \
425+
typedef m_class self_type; \
426+
\
419427
static void initialize_class() {} \
420428
\
421429
static ::godot::StringName &get_class_static() { \
@@ -425,6 +433,17 @@ public:
425433
\
426434
static ::godot::StringName &get_parent_class_static() { \
427435
return m_inherits::get_class_static(); \
436+
} \
437+
\
438+
static GDExtensionObjectPtr create(void *data) { \
439+
return nullptr; \
440+
} \
441+
\
442+
static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) { \
443+
return nullptr; \
444+
} \
445+
\
446+
static void free(void *data, GDExtensionClassInstancePtr ptr) { \
428447
} \
429448
\
430449
static void *_gde_binding_create_callback(void *p_token, void *p_instance) { \

include/godot_cpp/core/class_db.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class ClassDB {
170170

171171
template <class T, bool is_abstract>
172172
void ClassDB::_register_class(bool p_virtual, bool p_exposed) {
173+
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
173174
instance_binding_callbacks[T::get_class_static()] = &T::_gde_binding_callbacks;
174175

175176
// Register this class within our plugin

0 commit comments

Comments
 (0)