Skip to content

Commit

Permalink
Fixed crash on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Oct 20, 2024
1 parent 0f28a33 commit 7edb7ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Sources/Shared/Core/ITraceSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace Death

/** @brief Unregisters the sink and uninitializes logger if no sink left */
void DetachSink(ITraceSink* sink);

/** @brief Flushes and waits until all prior items are written to all sinks */
void Flush();
}
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/Shared/Core/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,11 @@ namespace Death { namespace Trace {
_internalLogger.DetachSink(sink);
}

void Flush()
{
_internalLogger.Flush();
}

}}

void DEATH_TRACE(TraceLevel level, const char* fmt, ...)
Expand Down
14 changes: 12 additions & 2 deletions Sources/nCine/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ namespace nCine

# if defined(WITH_BACKWARD)
if (__consoleType >= ConsoleType::EscapeCodes) {
//__eh.FeatureFlags |= Backward::Flags::ColorizeOutput;
__eh.FeatureFlags |= Backward::Flags::ColorizeOutput;
}
# endif
}
Expand All @@ -1022,7 +1022,7 @@ namespace nCine
if (__logFile = fs::Open(targetPath, FileAccess::Write)) {
# if defined(WITH_BACKWARD)
// Try to save crash info to log file
//__eh.Destination = static_cast<FileStream*>(__logFile.get())->GetHandle();
__eh.Destination = static_cast<FileStream*>(__logFile.get())->GetHandle();
# endif
} else {
__logFile = nullptr;
Expand Down Expand Up @@ -1094,6 +1094,16 @@ namespace nCine

void Application::ShutdownTrace()
{
# if !defined(DEATH_TARGET_EMSCRIPTEN)
if (__logFile != nullptr) {
Trace::Flush();
# if defined(WITH_BACKWARD)
__eh.Destination = nullptr;
# endif
__logFile = nullptr;
}
# endif

Trace::DetachSink(this);

# if defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)
Expand Down

0 comments on commit 7edb7ae

Please sign in to comment.