Merge pull request #81117 from AThousandShips/object_register_fix_3_x

[3.x] Add check to ensure registered classes are declared
This commit is contained in:
Rémi Verschelde 2023-09-06 13:04:46 +02:00
commit 5279566a1b
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 6 additions and 0 deletions

View file

@ -170,6 +170,7 @@ public:
template <class T> template <class T>
static void register_class() { static void register_class() {
GLOBAL_LOCK_FUNCTION; GLOBAL_LOCK_FUNCTION;
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
T::initialize_class(); T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static()); ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t); ERR_FAIL_COND(!t);
@ -182,6 +183,7 @@ public:
template <class T> template <class T>
static void register_virtual_class() { static void register_virtual_class() {
GLOBAL_LOCK_FUNCTION; GLOBAL_LOCK_FUNCTION;
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
T::initialize_class(); T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static()); ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t); ERR_FAIL_COND(!t);
@ -198,6 +200,7 @@ public:
template <class T> template <class T>
static void register_custom_instance_class() { static void register_custom_instance_class() {
GLOBAL_LOCK_FUNCTION; GLOBAL_LOCK_FUNCTION;
static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
T::initialize_class(); T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static()); ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t); ERR_FAIL_COND(!t);

View file

@ -269,6 +269,7 @@ private:
friend class ClassDB; \ friend class ClassDB; \
\ \
public: \ public: \
typedef m_class self_type; \
virtual String get_class() const { \ virtual String get_class() const { \
return String(#m_class); \ return String(#m_class); \
} \ } \
@ -407,6 +408,8 @@ class ObjectRC;
class Object { class Object {
public: public:
typedef Object self_type;
enum ConnectFlags { enum ConnectFlags {
CONNECT_DEFERRED = 1, CONNECT_DEFERRED = 1,