From af703492330d5b78938026a1e28098df48267f1c Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 10 Dec 2016 18:48:53 +0100 Subject: [PATCH] Changed: Destructor for CApplicationContext to display singletons still in memory --- code/nel/include/nel/misc/app_context.h | 1 + code/nel/src/misc/app_context.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/code/nel/include/nel/misc/app_context.h b/code/nel/include/nel/misc/app_context.h index df9165baf..bf73ddb83 100644 --- a/code/nel/include/nel/misc/app_context.h +++ b/code/nel/include/nel/misc/app_context.h @@ -108,6 +108,7 @@ namespace NLMISC { public: CApplicationContext(); + virtual ~CApplicationContext(); virtual void *getSingletonPointer(const std::string &singletonName); virtual void setSingletonPointer(const std::string &singletonName, void *ptr); diff --git a/code/nel/src/misc/app_context.cpp b/code/nel/src/misc/app_context.cpp index 5206681f9..a7381d026 100644 --- a/code/nel/src/misc/app_context.cpp +++ b/code/nel/src/misc/app_context.cpp @@ -124,6 +124,27 @@ CApplicationContext::CApplicationContext() contextReady(); } +CApplicationContext::~CApplicationContext() +{ +#ifdef NL_DEBUG + TSingletonRegistry::iterator it = _SingletonRegistry.begin(), iend = _SingletonRegistry.end(); + + while (it != iend) + { + // can't use nldebug there because it'll create new displayers + std::string message = toString("Instance '%s' still allocated at %p", it->first.c_str(), it->second); + +#ifdef NL_OS_WINDOWS + OutputDebugStringW(utf8ToWide(message)); +#else + printf("%s\n", message.c_str()); +#endif + + ++it; + } +#endif +} + void *CApplicationContext::getSingletonPointer(const std::string &singletonName) { TSingletonRegistry::iterator it(_SingletonRegistry.find(singletonName));