From 158d272e92e6541e028aec84bae860c0d8a7093b Mon Sep 17 00:00:00 2001 From: ragnar Date: Sun, 7 Jun 2026 14:11:27 +0300 Subject: [PATCH] fix(cgame): properly load 3 rubble-bounce sounds via for loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CG_RegisterSounds had a single line: cgs.media.sfx_rubbleBounce[i] = trap_S_RegisterSound( "sound/world/debris%i.wav" ); with two bugs: 1. `i` is the function-scope local from line 1182, uninitialized at this point — the value is stack garbage. UBSAN observed `i == 111` and `i == 162` across runs; the array is declared `sfxHandle_t[3]`, so the write lands ~100+ bytes past the array bound inside cgs.media, silently scrambling whichever member the offset hits. 2. The path string `"sound/world/debris%i.wav"` is passed literally to trap_S_RegisterSound (no va()), so even when the index doesn't trip, the engine looks for a file literally named `debris%i.wav` which doesn't exist — debris bounce sounds are NEVER loaded. Both bugs look like an incomplete copy-paste of the brass-sound blocks above, which are hand-unrolled with literal indices [0]/[1]/[2]. Replace with a 3-iteration loop using va() to format the path. After this fix, `sound/world/debris1.wav`..`debris3.wav` actually load and the rubble-bounce audio cue is restored. Not present in vanilla RTCW SP 2010 source drop — introduced post-drop in iortcw/RealRTCW lineage. --- code/cgame/cg_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/code/cgame/cg_main.c b/code/cgame/cg_main.c index 4e1efdc18..28a1257c7 100644 --- a/code/cgame/cg_main.c +++ b/code/cgame/cg_main.c @@ -1417,8 +1417,13 @@ static void CG_RegisterSounds( void ) { cgs.media.sfx_brassSound_wood[0] = trap_S_RegisterSound("sound/weapons/misc/shell_wood1.wav" ); cgs.media.sfx_brassSound_wood[1] = trap_S_RegisterSound("sound/weapons/misc/shell_wood2.wav" ); cgs.media.sfx_brassSound_wood[2] = trap_S_RegisterSound("sound/weapons/misc/shell_wood3.wav" ); - - cgs.media.sfx_rubbleBounce[i] = trap_S_RegisterSound("sound/world/debris%i.wav" ); + + { + int j; + for ( j = 0; j < 3; j++ ) { + cgs.media.sfx_rubbleBounce[j] = trap_S_RegisterSound( va( "sound/world/debris%i.wav", j + 1 ) ); + } + } cgs.media.sparkSounds[0] = trap_S_RegisterSound( "sound/world/saarc2.wav" ); cgs.media.sparkSounds[1] = trap_S_RegisterSound( "sound/world/arc2.wav" );