Skip to content

Commit

Permalink
Merge pull request #81117 from AThousandShips/object_register_fix_3_x
Browse files Browse the repository at this point in the history
[3.x] Add check to ensure registered classes are declared
  • Loading branch information
akien-mga committed Sep 6, 2023
2 parents 2a6c7fc + 4b205af commit 5279566
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class ClassDB {
template <class T>
static void register_class() {
GLOBAL_LOCK_FUNCTION;
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
Expand All @@ -182,6 +183,7 @@ class ClassDB {
template <class T>
static void register_virtual_class() {
GLOBAL_LOCK_FUNCTION;
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
Expand All @@ -198,6 +200,7 @@ class ClassDB {
template <class T>
static void register_custom_instance_class() {
GLOBAL_LOCK_FUNCTION;
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
Expand Down
3 changes: 3 additions & 0 deletions core/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private:
friend class ClassDB; \
\
public: \
typedef m_class self_type; \
virtual String get_class() const { \
return String(#m_class); \
} \
Expand Down Expand Up @@ -407,6 +408,8 @@ class ObjectRC;

class Object {
public:
typedef Object self_type;

enum ConnectFlags {

CONNECT_DEFERRED = 1,
Expand Down

0 comments on commit 5279566

Please sign in to comment.