Pārlūkot izejas kodu

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.
chefrolle695 11 mēneši atpakaļ
vecāks
revīzija
4b9ac76815
2 mainītis faili ar 8 papildinājumiem un 7 dzēšanām
  1. 3 5
      code/Common/DefaultLogger.cpp
  2. 5 2
      include/assimp/DefaultLogger.hpp

+ 3 - 5
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;
 }
 
 // ----------------------------------------------------------------------------------

+ 5 - 2
include/assimp/DefaultLogger.hpp

@@ -103,6 +103,9 @@ public:
      *  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 @@ public:
     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();
 
     // ----------------------------------------------------------------------