Skip to content

Commit edc148d

Browse files
committed
Skip Windows logging path before file sink is initialized
1 parent 450f06f commit edc148d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

include/ultra/logging.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,19 @@ inline void setLogFile(FILE* file) {
7171
inline void log(LogLevel level, const char* category, const char* format, ...) {
7272
if (level > g_log_level) return;
7373

74-
std::lock_guard<std::mutex> lock(g_log_mutex);
74+
#ifdef _WIN32
75+
// During early GUI startup on some Win10 systems, touching the shared
76+
// logging mutex/CRT stream path can crash. If no explicit file sink is set,
77+
// skip logging entirely.
7578
FILE* out = g_log_file;
7679
if (!out) {
77-
#ifdef _WIN32
78-
// GUI-subsystem processes can have an invalid stderr stream on Win10.
79-
// Avoid using stderr entirely on Windows unless an explicit log file is set.
8080
return;
81+
}
82+
std::lock_guard<std::mutex> lock(g_log_mutex);
8183
#else
82-
out = stderr;
84+
std::lock_guard<std::mutex> lock(g_log_mutex);
85+
FILE* out = g_log_file ? g_log_file : stderr;
8386
#endif
84-
}
8587

8688
// Get elapsed time in milliseconds
8789
auto now = std::chrono::steady_clock::now();

0 commit comments

Comments
 (0)