Преглед на файлове

Add protections against registering classes that didn't use GDCLASS()

(cherry picked from commit a61cdc88606fbd0230555f1657d0cd635ba4bb5b)
David Snopek преди 1 година
родител
ревизия
9d813310bb
променени са 2 файла, в които са добавени 16 реда и са изтрити 0 реда
  1. 15 0
      include/godot_cpp/classes/wrapped.hpp
  2. 1 0
      include/godot_cpp/core/class_db.hpp

+ 15 - 0
include/godot_cpp/classes/wrapped.hpp

@@ -170,6 +170,8 @@ protected:
 	}                                                                                                                                                                                  \
                                                                                                                                                                                        \
 public:                                                                                                                                                                                \
+	typedef m_class self_type;                                                                                                                                                         \
+                                                                                                                                                                                       \
 	static void initialize_class() {                                                                                                                                                   \
 		static bool initialized = false;                                                                                                                                               \
 		if (initialized) {                                                                                                                                                             \
@@ -372,6 +374,8 @@ protected:
 	}                                                                                                                      \
                                                                                                                            \
 public:                                                                                                                    \
+	typedef m_class self_type;                                                                                             \
+                                                                                                                           \
 	static void initialize_class() {}                                                                                      \
                                                                                                                            \
 	static ::godot::StringName &get_class_static() {                                                                       \
@@ -381,6 +385,17 @@ public:
                                                                                                                            \
 	static ::godot::StringName &get_parent_class_static() {                                                                \
 		return m_inherits::get_class_static();                                                                             \
+	}                                                                                                                      \
+                                                                                                                           \
+	static GDExtensionObjectPtr create(void *data) {                                                                       \
+		return nullptr;                                                                                                    \
+	}                                                                                                                      \
+                                                                                                                           \
+	static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) {                                    \
+		return nullptr;                                                                                                    \
+	}                                                                                                                      \
+                                                                                                                           \
+	static void free(void *data, GDExtensionClassInstancePtr ptr) {                                                        \
 	}                                                                                                                      \
                                                                                                                            \
 	static void *_gde_binding_create_callback(void *p_token, void *p_instance) {                                           \

+ 1 - 0
include/godot_cpp/core/class_db.hpp

@@ -173,6 +173,7 @@ public:
 
 template <class T, bool is_abstract>
 void ClassDB::_register_class(bool p_virtual) {
+	static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
 	instance_binding_callbacks[T::get_class_static()] = &T::_gde_binding_callbacks;
 
 	// Register this class within our plugin