mirror of
https://github.com/mehah/otclient
synced 2026-08-15 16:29:06 -04:00
fix(sound): initialize effectSlot and fix OpenAL EFX slot binding (#1805)
Bug Fixes: - Improved audio effect handling when effects or sound sources are unavailable. - Ensured removing an audio effect safely updates the sound source and avoids invalid audio operations. - Preserved error reporting for failed audio effect operations.
This commit is contained in:
parent
67874d6694
commit
8f55d88980
2 changed files with 15 additions and 10 deletions
|
|
@ -34,7 +34,7 @@ SoundSource::SoundSource()
|
|||
|
||||
SoundSource::~SoundSource()
|
||||
{
|
||||
if (m_effectId != 0) {
|
||||
if (m_effectSlot != 0) {
|
||||
removeEffect();
|
||||
}
|
||||
if (m_sourceId != 0) {
|
||||
|
|
@ -169,8 +169,11 @@ void SoundSource::update()
|
|||
|
||||
void SoundSource::setEffect(const SoundEffectPtr soundEffect)
|
||||
{
|
||||
m_effectId = soundEffect->m_effectId;
|
||||
alSource3i(m_sourceId, AL_AUXILIARY_SEND_FILTER, static_cast<ALint>(soundEffect->m_effectId), 0, AL_FILTER_NULL);
|
||||
if (!soundEffect || m_sourceId == 0)
|
||||
return;
|
||||
|
||||
m_effectSlot = soundEffect->m_effectSlot;
|
||||
alSource3i(m_sourceId, AL_AUXILIARY_SEND_FILTER, static_cast<ALint>(soundEffect->m_effectSlot), 0, AL_FILTER_NULL);
|
||||
const ALenum err = alGetError();
|
||||
if (err != AL_NO_ERROR) {
|
||||
g_logger.error("Failed to set effect on source: {}", alGetString(err));
|
||||
|
|
@ -179,12 +182,14 @@ void SoundSource::setEffect(const SoundEffectPtr soundEffect)
|
|||
|
||||
void SoundSource::removeEffect()
|
||||
{
|
||||
if (m_effectId != 0) {
|
||||
m_effectId = 0;
|
||||
alSource3i(m_sourceId, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL);
|
||||
const ALenum err = alGetError();
|
||||
if (err != AL_NO_ERROR) {
|
||||
g_logger.error("Failed to remove effect on source: {}", alGetString(err));
|
||||
if (m_effectSlot != 0) {
|
||||
m_effectSlot = 0;
|
||||
if (m_sourceId != 0) {
|
||||
alSource3i(m_sourceId, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL);
|
||||
const ALenum err = alGetError();
|
||||
if (err != AL_NO_ERROR) {
|
||||
g_logger.error("Failed to remove effect on source: {}", alGetString(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ protected:
|
|||
float m_fadeTime{ 0 };
|
||||
float m_fadeGain{ 0 };
|
||||
float m_gain{ 1.f };
|
||||
uint m_effectId;
|
||||
uint m_effectSlot{ 0 };
|
||||
|
||||
FadeState m_fadeState{ NoFading };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue