diff options
author | Chris Robinson <[email protected]> | 2018-11-20 05:01:08 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-20 05:01:08 -0800 |
commit | 1df42c4a0f988c2736e9d2d2929d0f23ad2538be (patch) | |
tree | e036f53082ee4174a687130a98afebb0b7a5194f /Alc/alc.cpp | |
parent | 66fdd027d027058792d56da741a7660d8646c9df (diff) |
Use a unique_ptr for the default effect slot
Diffstat (limited to 'Alc/alc.cpp')
-rw-r--r-- | Alc/alc.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 56a581fd..3247e14c 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2255,7 +2255,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(context->DefaultSlot) { - ALeffectslot *slot = context->DefaultSlot; + ALeffectslot *slot = context->DefaultSlot.get(); EffectState *state = slot->Effect.State; state->mOutBuffer = device->Dry.Buffer; @@ -2497,6 +2497,11 @@ static ALCboolean VerifyDevice(ALCdevice **device) } +ALCcontext_struct::ALCcontext_struct(ALCdevice *device) + : Device{device} +{ +} + /* InitContext * * Initializes context fields @@ -2516,7 +2521,7 @@ static ALvoid InitContext(ALCcontext *Context) auxslots = static_cast<ALeffectslotArray*>(al_calloc(DEF_ALIGN, FAM_SIZE(struct ALeffectslotArray, slot, 1))); auxslots->count = 1; - auxslots->slot[0] = Context->DefaultSlot; + auxslots->slot[0] = Context->DefaultSlot.get(); } else { @@ -2584,10 +2589,8 @@ ALCcontext_struct::~ALCcontext_struct() } TRACE("Freed " SZFMT " context property object%s\n", count, (count==1)?"":"s"); - delete DefaultSlot; - DefaultSlot = nullptr; - al_free(ActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed)); + DefaultSlot = nullptr; ReleaseALSources(this); std::for_each(SourceList.begin(), SourceList.end(), @@ -3675,12 +3678,11 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin if(DefaultEffect.type != AL_EFFECT_NULL && device->Type == Playback) { - ALContext->DefaultSlot = new ALeffectslot{}; - if(InitEffectSlot(ALContext->DefaultSlot) == AL_NO_ERROR) - aluInitEffectPanning(ALContext->DefaultSlot); + ALContext->DefaultSlot.reset(new ALeffectslot{}); + if(InitEffectSlot(ALContext->DefaultSlot.get()) == AL_NO_ERROR) + aluInitEffectPanning(ALContext->DefaultSlot.get()); else { - delete ALContext->DefaultSlot; ALContext->DefaultSlot = nullptr; ERR("Failed to initialize the default effect slot\n"); } @@ -3713,8 +3715,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin if(ALContext->DefaultSlot) { - if(InitializeEffect(ALContext, ALContext->DefaultSlot, &DefaultEffect) == AL_NO_ERROR) - UpdateEffectSlotProps(ALContext->DefaultSlot, ALContext); + if(InitializeEffect(ALContext, ALContext->DefaultSlot.get(), &DefaultEffect) == AL_NO_ERROR) + UpdateEffectSlotProps(ALContext->DefaultSlot.get(), ALContext); else ERR("Failed to initialize the default effect\n"); } |