From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Grigoris Pavlakis Date: Fri, 17 Jun 2022 19:29:00 +0300 Subject: [PATCH] Defer sound system initialization until main() The original VVVVVV source code initializes the sound subsystem during global variable initialization. Technically speaking, the order of initialization of global variables is unspecified. This results in SerenityOS's dynamic linker to call Mix_OpenAudio() (which uses EventLoop under the hood) before all global variable initializers finish executing, resulting in an inconsistent state that causes assertion failure. This patch moves initialization of the culprit sound system to a separate method, which is called first thing inside main(), thus preventing the setup from happening during musicclass's initialization in the global scope, which causes the aforementioned crash. --- desktop_version/src/SoundSystem.cpp | 4 ++++ desktop_version/src/SoundSystem.h | 1 + desktop_version/src/main.cpp | 1 + 3 files changed, 6 insertions(+) diff --git a/desktop_version/src/SoundSystem.cpp b/desktop_version/src/SoundSystem.cpp index 8c5f962..056d946 100644 --- a/desktop_version/src/SoundSystem.cpp +++ b/desktop_version/src/SoundSystem.cpp @@ -52,6 +52,10 @@ SoundTrack::SoundTrack(const char* fileName) } SoundSystem::SoundSystem(void) +{ +} + +void SoundSystem::initialize(void) { int audio_rate = 44100; Uint16 audio_format = AUDIO_S16SYS; diff --git a/desktop_version/src/SoundSystem.h b/desktop_version/src/SoundSystem.h index 0cf3b84..f88e15b 100644 --- a/desktop_version/src/SoundSystem.h +++ b/desktop_version/src/SoundSystem.h @@ -23,6 +23,7 @@ class SoundSystem { public: SoundSystem(void); + void initialize(void); }; #endif /* SOUNDSYSTEM_H */ diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index b97270f..49bd853 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -341,6 +341,7 @@ static void cleanup(void); int main(int argc, char *argv[]) { + music.soundSystem.initialize(); char* baseDir = NULL; char* assetsPath = NULL;