From 73ab9d46c88f034a32a6fb174e98fd23dec1ff98 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 24 Aug 2020 16:34:53 -0700 Subject: Use an intrusive_ptr to hold the unapplied effect state --- al/auxeffectslot.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'al/auxeffectslot.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index c5f9a295..bfacb290 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -693,8 +693,6 @@ ALeffectslot::~ALeffectslot() delete props; } - if(Effect.State) - Effect.State->release(); if(Params.mEffectState) Params.mEffectState->release(); } @@ -703,11 +701,12 @@ ALenum ALeffectslot::init() { EffectStateFactory *factory{getFactoryByType(Effect.Type)}; if(!factory) return AL_INVALID_VALUE; - Effect.State = factory->create(); + + Effect.State.reset(factory->create()); if(!Effect.State) return AL_OUT_OF_MEMORY; Effect.State->add_ref(); - Params.mEffectState = Effect.State; + Params.mEffectState = Effect.State.get(); return AL_NO_ERROR; } @@ -722,7 +721,7 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context) ERR("Failed to find factory for effect type 0x%04x\n", newtype); return AL_INVALID_ENUM; } - EffectState *State{factory->create()}; + al::intrusive_ptr State{factory->create()}; if(!State) return AL_OUT_OF_MEMORY; ALCdevice *Device{context->mDevice.get()}; @@ -744,8 +743,7 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context) Effect.Props = effect->Props; } - Effect.State->release(); - Effect.State = State; + Effect.State = std::move(State); } else if(effect) Effect.Props = effect->Props; @@ -786,8 +784,7 @@ void ALeffectslot::updateProps(ALCcontext *context) /* Swap out any stale effect state object there may be in the container, to * delete it. */ - Effect.State->add_ref(); - props->State.reset(Effect.State); + props->State = Effect.State; /* Set the new container for updating internal parameters. */ props = Params.Update.exchange(props, std::memory_order_acq_rel); -- cgit v1.2.3