Skip to content

Commit 6946e99

Browse files
authored
Fix #4259: report failed sound effects honestly on Windows 11 24H2 (#4859)
#### Summary On Windows 11 24H2, `BASS_ChannelSetFX(BASS_FX_DX8_I3DL2REVERB)` fails with `BASS_ERROR_NOFX` (41) because the OS dropped the I3DL2 DMO. `ApplyFxEffects` was swallowing the failure and storing `INVALID_FX_HANDLE`, so the next `BASS_FXSetParameters` rejected the bogus handle with `BASS_ERROR_HANDLE` (5). Scripts saw a misleading "BASS error 5" on `roomHF`. `ApplyFxEffects` now logs the real BASS error and clears `m_EnabledEffects[i]` when the handle is `INVALID_FX_HANDLE`. `setSoundEffectEnabled` returns the BASS-effective outcome via `CBassAudio::IsFxEffectEnabled`, so `getSoundEffects` and the `setSoundEffectParameter` "must be enabled" gate report the truth. Same fix on `CClientPlayerVoice`. #### Motivation Fixes #4259. `roomHF` is just the first I3DL2 parameter people try; any of the 12 errors identically. Code 5 (`BASS_ERROR_HANDLE`) was the latest BASS error from the failed `BASS_FXSetParameters`, not the underlying 41 (`BASS_ERROR_NOFX`) from the much earlier `BASS_ChannelSetFX`, which was never logged. Per [un4seen docs](https://www.un4seen.com/doc/bass/BASS_ChannelSetFX.html): *"Windows 11 24H2 removed the I3DL2REVERB effect, so it should be avoided if you need to run on the latest Windows."* BASS does not emulate it on Windows. #### Test plan - [x] Win 11 24H2: `setSoundEffectEnabled(s, "i3dl2reverb", true)` returns `false`; console logs `BASS ERROR 41 in BASS_ChannelSetFX (effect 6)`. - [x] `setSoundEffectParameter(s, "i3dl2reverb", "roomHF", -100)` errors with `Effect's parameters can't be set unless it's enabled` instead of `BASS Error 5`. - [x] `getSoundEffects(s).i3dl2reverb` returns `false` after the failed enable. - [x] Other DX8 effects (chorus, echo, flanger, etc.) still enable, parameterise, and disable normally. - [x] Re-enabling after a failed enable stays failed; no dangling handle. - [x] Same scenarios pass on the player-voice path. #### Checklist * [x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines). * [x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.
1 parent 01c72fc commit 6946e99

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

Client/mods/deathmatch/logic/CBassAudio.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,13 @@ void CBassAudio::ApplyFxEffects()
11671167
// Switch on
11681168
m_FxEffects[i] = BASS_ChannelSetFX(m_pSound, i, 0);
11691169
if (!m_FxEffects[i])
1170+
{
1171+
// Effect could not be wired up by BASS. Notable case: Windows 11
1172+
// 24H2 removed BASS_FX_DX8_I3DL2REVERB at the OS level (#4259), so
1173+
// BASS_ChannelSetFX returns 0 with BASS_ERROR_NOFX.
1174+
g_pCore->GetConsole()->Printf("BASS ERROR %d in BASS_ChannelSetFX (effect %u)", BASS_ErrorGetCode(), i);
11701175
m_FxEffects[i] = INVALID_FX_HANDLE;
1176+
}
11711177
}
11721178
else if (!m_EnabledEffects[i] && m_FxEffects[i])
11731179
{
@@ -1176,6 +1182,11 @@ void CBassAudio::ApplyFxEffects()
11761182
BASS_ChannelRemoveFX(m_pSound, m_FxEffects[i]);
11771183
m_FxEffects[i] = 0;
11781184
}
1185+
1186+
// Mirror failure into m_EnabledEffects so IsFxEffectEnabled() reports the
1187+
// truth and re-enable requests don't silently leave a dangling handle.
1188+
if (m_FxEffects[i] == INVALID_FX_HANDLE)
1189+
m_EnabledEffects[i] = 0;
11791190
}
11801191
}
11811192

Client/mods/deathmatch/logic/CBassAudio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class CBassAudio
7777
void SetFxEffects(int* pEnabledEffects, uint iNumElements);
7878
BOOL SetFxParameters(uint iFxEffect, void* params);
7979
BOOL GetFxParameters(uint iFxEffect, void* params);
80+
bool IsFxEffectEnabled(uint iFxEffect) const { return iFxEffect < NUMELMS(m_EnabledEffects) && m_EnabledEffects[iFxEffect] != 0; }
8081
SString GetMetaTags(const SString& strFormat);
8182
uint GetReachedEndCount();
8283
bool IsFreed();

Client/mods/deathmatch/logic/CClientPlayerVoice.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,12 @@ bool CClientPlayerVoice::SetFxEffect(uint uiFxEffect, bool bEnable)
361361

362362
// Apply if active
363363
if (m_pBassPlaybackStream)
364+
{
364365
ApplyFxEffects();
366+
// ApplyFxEffects clears m_EnabledEffects[i] when BASS rejects the effect
367+
// (e.g. I3DL2REVERB on Windows 11 24H2, #4259), so report the truth.
368+
return (m_EnabledEffects[uiFxEffect] != 0) == bEnable;
369+
}
365370

366371
return true;
367372
}
@@ -378,7 +383,12 @@ void CClientPlayerVoice::ApplyFxEffects()
378383
// Switch on
379384
m_FxEffects[i] = BASS_ChannelSetFX(m_pBassPlaybackStream, i, 0);
380385
if (!m_FxEffects[i])
386+
{
387+
// Effect could not be wired up by BASS (e.g. Windows 11 24H2
388+
// removed BASS_FX_DX8_I3DL2REVERB at the OS level, #4259).
389+
g_pCore->GetConsole()->Printf("BASS ERROR %d in BASS_ChannelSetFX (effect %u)", BASS_ErrorGetCode(), i);
381390
m_FxEffects[i] = INVALID_FX_HANDLE;
391+
}
382392
}
383393
else
384394
{
@@ -390,6 +400,11 @@ void CClientPlayerVoice::ApplyFxEffects()
390400
m_FxEffects[i] = 0;
391401
}
392402
}
403+
404+
// Mirror failure into m_EnabledEffects so IsFxEffectEnabled() reports
405+
// the truth and re-enable requests don't silently leave a dangling handle.
406+
if (m_FxEffects[i] == INVALID_FX_HANDLE)
407+
m_EnabledEffects[i] = 0;
393408
}
394409
}
395410

Client/mods/deathmatch/logic/CClientSound.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,12 @@ bool CClientSound::SetFxEffect(uint uiFxEffect, bool bEnable)
679679
m_EnabledEffects[uiFxEffect] = bEnable;
680680

681681
if (m_pAudio)
682+
{
682683
m_pAudio->SetFxEffects(&m_EnabledEffects[0], NUMELMS(m_EnabledEffects));
684+
// Report the BASS-effective outcome: an effect the OS doesn't provide
685+
// (e.g. I3DL2REVERB on Windows 11 24H2, #4259) won't actually engage.
686+
return m_pAudio->IsFxEffectEnabled(uiFxEffect) == bEnable;
687+
}
683688

684689
return true;
685690
}
@@ -688,6 +693,8 @@ bool CClientSound::IsFxEffectEnabled(uint uiFxEffect)
688693
{
689694
if (uiFxEffect >= NUMELMS(m_EnabledEffects))
690695
return false;
696+
if (m_pAudio)
697+
return m_pAudio->IsFxEffectEnabled(uiFxEffect);
691698
return m_EnabledEffects[uiFxEffect] ? true : false;
692699
}
693700

0 commit comments

Comments
 (0)