luciusDXL / TheForceEngine

Modern "Jedi Engine" replacement supporting Dark Forces, mods, and in the future Outlaws.
https://TheForceEngine.github.io
GNU General Public License v2.0
946 stars 71 forks source link

[Linux] No music during cutscenes #369

Closed putridpete closed 7 months ago

putridpete commented 8 months ago

Hey there, I just compiled from source on Arch Linux and there is no music playing at all during cutscenes. I couldn't find any specific issue mentioning this, neither here on github or the projects forum.

Here's the output from the terminal, in which the intro plays without any music:

[Main] The Force Engine v1.09.540-148-g1a4a6784 
[Paths] Program Path: "/home/peter/.bin/tfe/"
[Paths] Program Data: "/home/peter/.local/share/TheForceEngine/"
[Paths] User Documents: "/home/peter/.local/share/TheForceEngine/"
[Paths] Source Data: "/home/peter/.bin/tfe/.data/"
[Startup] TFE_System::init
[Display] Fullscreen enabled.
[RenderBackend] OpenGL Device Tier: 3
[Startup] TFE_AudioSystem::init
[Audio] SDLAudio using interface 'pulseaudio'
[Audio] Device 00: Razer USB Sound Card Analog Stereo
[Audio] Starting up audio stream for device '<autoselect>'
[Startup] TFE_MidiPlayer::init
[Startup] TFE_Image::init
[Startup] TFE_FrontEndUI::init
[MemoryRegion] Allocated new memory block in region 'game' - new size is 1 blocks, total size is '8388608'
[MemoryRegion] Allocated new memory block in region 'level' - new size is 1 blocks, total size is '8388608'
[Progam Flow] The Force Engine Game Loop Started
[Game] Dark Forces Version: 1.0 (Build 1)
[MemoryRegion] Allocated new memory block in region 'Landru' - new size is 1 blocks, total size is '4194304'
[MemoryRegion] Allocated new memory block in region 'Cutscene' - new size is 1 blocks, total size is '8388608'
[Error : iMuse] null sound addr in StartSound()
[Audio] Shutdown
[Audio] Stop Audio Stream.
[MidiPlayer] Shutdown
[Progam Flow] The Force Engine Game Loop Ended.

I've tested this under kernels 6.1.62-1-lts and 6.6.1.zen1-1 with the same result. Sound works fine during videos and both music and sound work fine during levels. I'm wondering if this is an issue with my configuration or if I'm missing anything in particular inside my data folder. I've simply copied it whole from a previous GOG installation and placed it next to the binary and pointed towards it using the source port's menu. Any help would be appreciated.

mlauss2 commented 8 months ago

Does it work if you configure with "cmake -DCMAKE_BUILD_TYPE=Debug" ? This here [Error : iMuse] null sound addr in StartSound() is suspicious

mlauss2 commented 8 months ago

I can repro; this part of CMakeLists.txt needs to be deleted:

## gcc-12+ and clang-15+ have a feature to automatically zero all variables/members/...
## this mimics what modern MSVC does.  Enable it for release builds (i.e.
## when not debugging to not hide any real bugs).
if(CMAKE_BUILD_TYPE STREQUAL "Release")
    check_cxx_compiler_flag("-ftrivial-auto-var-init=zero" COMPILER_ENABLE_AUTOZERO)
endif()

as gcc now just DCEs a bunch of code. I'll take a look.

putridpete commented 8 months ago

Hey there, thanks for the response. Sorry I'm late, but I can confirm that after recompiling with that part removed from CMakeLists.txt, music is restored in all cutscenes!

mlauss2 commented 7 months ago

I had some time to properly debug this; this here fixes the code bug:

diff --git a/TheForceEngine/TFE_DarkForces/Landru/lmusic.cpp b/TheForceEngine/TFE_DarkForces/Landru/lmusic.cpp
index a3cc6fdf..6eb11bfd 100644
--- a/TheForceEngine/TFE_DarkForces/Landru/lmusic.cpp
+++ b/TheForceEngine/TFE_DarkForces/Landru/lmusic.cpp
@@ -72,9 +72,9 @@ namespace TFE_DarkForces

                s32 index = 0;
                char name[80];
+               s32 sequence = 0;
                while (fileData)
                {
-                       s32 sequence;
                        if (sscanf(fileData, "SEQUENCE: %d", &sequence) == 1)
                        {
                                index = 0;

since "sequence" is reinitialized every iteration of the loop, gcc saw that it was never anything else than zero, the stores to "s_sequences" were removed due to being dead code (code inside the 'if (sequence && ...)' could never be executed)