From 9df6edc7d78ff49d471131c8095f7c1e05a6e895 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 (cherry picked from commit e1150bd912bd6076b8a94544c0ec32f75344976e) --- core/engine.cpp | 10 ++++++++++ core/engine.h | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/engine.cpp b/core/engine.cpp index 454e889255b..9f68b9ccef2 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -236,3 +236,13 @@ Engine::Engine() { _frame_step = 0; editor_hint = false; } + +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/engine.h b/core/engine.h index 4bb3f73bff3..4345a53db3d 100644 --- a/core/engine.h +++ b/core/engine.h @@ -42,10 +42,7 @@ public: struct Singleton { StringName name; Object *ptr; - Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) : - name(p_name), - ptr(p_ptr) { - } + Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL); }; private: