From 6b0c704b1922c41c645f70eed9f6fbd21bfa3f28 Mon Sep 17 00:00:00 2001 From: majcosta <34732933+majcosta@users.noreply.github.com> Date: Wed, 18 Jan 2023 04:33:06 -0300 Subject: [PATCH] avoid static initialization order fiasco in soundman.cpp (#80) 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 f0f1cba1..22077f74 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) {