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 | |
parent | 66fdd027d027058792d56da741a7660d8646c9df (diff) |
Use a unique_ptr for the default effect slot
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alc.cpp | 24 | ||||
-rw-r--r-- | Alc/alcontext.h | 5 | ||||
-rw-r--r-- | Alc/alu.cpp | 4 |
3 files changed, 18 insertions, 15 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"); } diff --git a/Alc/alcontext.h b/Alc/alcontext.h index 5eec2e96..f174f324 100644 --- a/Alc/alcontext.h +++ b/Alc/alcontext.h @@ -1,6 +1,7 @@ #ifndef ALCONTEXT_H #define ALCONTEXT_H +#include <memory> #include <thread> #include "AL/al.h" @@ -106,7 +107,7 @@ struct ALCcontext_struct { void *EventParam{nullptr}; /* Default effect slot */ - ALeffectslot *DefaultSlot{nullptr}; + std::unique_ptr<ALeffectslot> DefaultSlot; ALCdevice *const Device; const ALCchar *ExtensionList{nullptr}; @@ -116,7 +117,7 @@ struct ALCcontext_struct { ALlistener Listener{}; - ALCcontext_struct(ALCdevice *device) : Device{device} { } + ALCcontext_struct(ALCdevice *device); ALCcontext_struct(const ALCcontext_struct&) = delete; ALCcontext_struct& operator=(const ALCcontext_struct&) = delete; ~ALCcontext_struct(); diff --git a/Alc/alu.cpp b/Alc/alu.cpp index cc48a4bf..68387f7b 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -1043,7 +1043,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *props, c { SendSlots[i] = props->Send[i].Slot; if(!SendSlots[i] && i == 0) - SendSlots[i] = ALContext->DefaultSlot; + SendSlots[i] = ALContext->DefaultSlot.get(); if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL) { SendSlots[i] = NULL; @@ -1117,7 +1117,7 @@ void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *props, cons { SendSlots[i] = props->Send[i].Slot; if(!SendSlots[i] && i == 0) - SendSlots[i] = ALContext->DefaultSlot; + SendSlots[i] = ALContext->DefaultSlot.get(); if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL) { SendSlots[i] = NULL; |