From e128cb47ac7ec844da9ca7bc5767f4c96e8d1b21 Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Mon, 16 Jan 2023 17:08:00 -0300 Subject: [PATCH] avoid static initialization order fiasco in soundman.cpp when running the cmake Debug build instead of the ja2_vs2019.sln file s_SoundLog is undefined. the most likely reason for that is that static objects in global scope have unspecified initialization order. the problem is fixed if the static SoundLog object is created inside the SoundLog(CHAR8*) function instead. also remove the comment whose meaning apparently has been lost to the sands of time --- Standard Gaming Platform/soundman.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Standard Gaming Platform/soundman.cpp b/Standard Gaming Platform/soundman.cpp index f0f1cba17..22077f741 100644 --- a/Standard Gaming Platform/soundman.cpp +++ b/Standard Gaming Platform/soundman.cpp @@ -1852,16 +1852,6 @@ UINT32 uiCount; return(FALSE); } -// Lesh modifications -// Sound debug -static struct SoundLog { - sgp::Logger_ID id; - SoundLog() { - id = sgp::Logger::instance().createLogger(); - sgp::Logger::instance().connectFile(id, SndDebugFileName, true, sgp::Logger::FLUSH_ON_DELETE); - } -} s_SoundLog; - //***************************************************************************************** // SoundLog // Writes string into log file @@ -1872,6 +1862,13 @@ static struct SoundLog { //***************************************************************************************** void SoundLog(CHAR8 *strMessage) { + static struct SoundLog { + sgp::Logger_ID id; + SoundLog() { + id = sgp::Logger::instance().createLogger(); + sgp::Logger::instance().connectFile(id, SndDebugFileName, true, sgp::Logger::FLUSH_ON_DELETE); + } + } s_SoundLog; #ifndef USE_VFS if ((SndDebug = fopen(SndDebugFileName, "a+t")) != NULL) {