From e1150bd912bd6076b8a94544c0ec32f75344976e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Thu, 19 Nov 2020 11:46:05 +0100 Subject: [PATCH] Warn about singleton being a Reference --- core/config/engine.cpp | 10 ++++++++++ core/config/engine.h | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/config/engine.cpp b/core/config/engine.cpp index b0037ffb370..8e2ab094b08 100644 --- a/core/config/engine.cpp +++ b/core/config/engine.cpp @@ -219,3 +219,13 @@ Engine *Engine::get_singleton() { Engine::Engine() { singleton = this; } + +Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr) : + name(p_name), + ptr(p_ptr) { +#ifdef DEBUG_ENABLED + if (Object::cast_to(p_ptr)) { + ERR_PRINT("A class intended to be used as a singleton must *not* inherit from Reference."); + } +#endif +} diff --git a/core/config/engine.h b/core/config/engine.h index 1d3d963b394..0d9aa02f286 100644 --- a/core/config/engine.h +++ b/core/config/engine.h @@ -41,10 +41,7 @@ public: struct Singleton { StringName name; Object *ptr; - Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr) : - name(p_name), - ptr(p_ptr) { - } + Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr); }; private: