Don't pass an ALeffect to ALeffectslot::initEffect

This commit is contained in:
Chris Robinson 2022-02-07 08:47:55 -08:00
parent 4f7799f1ae
commit b09aab8426
3 changed files with 19 additions and 12 deletions

View File

@ -582,9 +582,14 @@ START_API_FUNC
{
std::lock_guard<std::mutex> ___{device->EffectLock};
ALeffect *effect{value ? LookupEffect(device, static_cast<ALuint>(value)) : nullptr};
if(!(value == 0 || effect != nullptr))
SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid effect ID %u", value);
err = slot->initEffect(effect, context.get());
if(effect)
err = slot->initEffect(effect->type, effect->Props, context.get());
else
{
if(value != 0)
SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid effect ID %u", value);
err = slot->initEffect(AL_EFFECT_NULL, EffectProps{}, context.get());
}
}
if UNLIKELY(err != AL_NO_ERROR)
{
@ -939,9 +944,10 @@ ALeffectslot::~ALeffectslot()
mSlot.mEffectState->release();
}
ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
ALenum ALeffectslot::initEffect(ALenum effectType, const EffectProps &effectProps,
ALCcontext *context)
{
EffectSlotType newtype{EffectSlotTypeFromEnum(effect ? effect->type : AL_EFFECT_NULL)};
EffectSlotType newtype{EffectSlotTypeFromEnum(effectType)};
if(newtype != Effect.Type)
{
EffectStateFactory *factory{getFactoryByType(newtype)};
@ -961,12 +967,12 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
}
Effect.Type = newtype;
Effect.Props = effect ? effect->Props : EffectProps{};
Effect.Props = effectProps;
Effect.State = std::move(state);
}
else if(effect)
Effect.Props = effect->Props;
else if(newtype != EffectSlotType::None)
Effect.Props = effectProps;
/* Remove state references from old effect slot property updates. */
EffectSlotProps *props{context->mFreeEffectslotProps.load()};
@ -1726,8 +1732,7 @@ void ALeffectslot::eax_set_effect_slot_effect(
std::lock_guard<std::mutex> effect_slot_lock{eax_al_context_->mEffectSlotLock};
std::lock_guard<std::mutex> effect_lock{device.EffectLock};
const auto error = initEffect(&effect, eax_al_context_);
const auto error = initEffect(effect.type, effect.Props, eax_al_context_);
if (error != AL_NO_ERROR)
{
ERR(EAX_PREFIX "%s\n", "Failed to initialize an effect.");

View File

@ -65,7 +65,7 @@ struct ALeffectslot {
ALeffectslot& operator=(const ALeffectslot&) = delete;
~ALeffectslot();
ALenum initEffect(ALeffect *effect, ALCcontext *context);
ALenum initEffect(ALenum effectType, const EffectProps &effectProps, ALCcontext *context);
void updateProps(ALCcontext *context);
/* This can be new'd for the context's default effect slot. */

View File

@ -3052,7 +3052,9 @@ START_API_FUNC
if(ALeffectslot *slot{context->mDefaultSlot.get()})
{
if(slot->initEffect(&ALCcontext::sDefaultEffect, context.get()) == AL_NO_ERROR)
ALenum sloterr{slot->initEffect(ALCcontext::sDefaultEffect.type,
ALCcontext::sDefaultEffect.Props, context.get())};
if(sloterr == AL_NO_ERROR)
slot->updateProps(context.get());
else
ERR("Failed to initialize the default effect\n");