Skip to content

Commit

Permalink
Fixed bug in DefaultLogger::set: (assimp#5826)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chefrolle695 authored Oct 17, 2024
1 parent 2591d0e commit 4b9ac76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 3 additions & 5 deletions code/Common/DefaultLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

// ----------------------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions include/assimp/DefaultLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();

// ----------------------------------------------------------------------
Expand Down

0 comments on commit 4b9ac76

Please sign in to comment.