From 4b9ac768155419203d13b9f2f67449f02e817c60 Mon Sep 17 00:00:00 2001 From: chefrolle695 Date: Thu, 17 Oct 2024 21:14:14 +0200 Subject: [PATCH] Fixed bug in DefaultLogger::set: (#5826) assigning s_pNullLogger to the parameter "logger" is definitely wrong. However, custom logger previously set from user must not be deleted. The user itself must handle allocation / deallocation. --- code/Common/DefaultLogger.cpp | 8 +++----- include/assimp/DefaultLogger.hpp | 7 +++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/code/Common/DefaultLogger.cpp b/code/Common/DefaultLogger.cpp index 828e326e2a..86a0896b22 100644 --- a/code/Common/DefaultLogger.cpp +++ b/code/Common/DefaultLogger.cpp @@ -221,13 +221,11 @@ void DefaultLogger::set(Logger *logger) { #endif if (nullptr == logger) { - logger = &s_pNullLogger; + m_pLogger = &s_pNullLogger; } - if (nullptr != m_pLogger && !isNullLogger()) { - delete m_pLogger; + else { + m_pLogger = logger; } - - DefaultLogger::m_pLogger = logger; } // ---------------------------------------------------------------------------------- diff --git a/include/assimp/DefaultLogger.hpp b/include/assimp/DefaultLogger.hpp index b43eebb706..bffaa7c09d 100644 --- a/include/assimp/DefaultLogger.hpp +++ b/include/assimp/DefaultLogger.hpp @@ -103,6 +103,9 @@ class ASSIMP_API DefaultLogger : public Logger { * your needs. If the provided message formatting is OK for you, * it's much easier to use #create() and to attach your own custom * output streams to it. + * Since set is intended to be used for custom loggers, the user is + * responsible for instantiation and destruction (new / delete). + * Before deletion of the custom logger, set(nullptr); must be called. * @param logger Pass NULL to setup a default NullLogger*/ static void set(Logger *logger); @@ -120,8 +123,8 @@ class ASSIMP_API DefaultLogger : public Logger { static bool isNullLogger(); // ---------------------------------------------------------------------- - /** @brief Kills the current singleton logger and replaces it with a - * #NullLogger instance. */ + /** @brief Kills and deletes the current singleton logger and replaces + * it with a #NullLogger instance. */ static void kill(); // ----------------------------------------------------------------------