diff options
author | Chris Robinson <[email protected]> | 2022-03-30 04:49:29 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-03-30 05:01:06 -0700 |
commit | 6718a49486b307ad938b707549ac1dfb78504300 (patch) | |
tree | f72ac05b3ff23f4e2f4a5fadd8eb44d4967cb8de | |
parent | 9537c771054f6aa9445b1f3ddeb8abb348a2eb83 (diff) |
Replace a few asserts with actual checks or ASSUME()
-rw-r--r-- | al/auxeffectslot.cpp | 2 | ||||
-rw-r--r-- | al/source.cpp | 12 | ||||
-rw-r--r-- | core/hrtf.cpp | 3 |
3 files changed, 9 insertions, 8 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index c1577679..c33fb149 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -915,7 +915,7 @@ END_API_FUNC ALeffectslot::ALeffectslot() { EffectStateFactory *factory{getFactoryByType(EffectSlotType::None)}; - assert(factory != nullptr); + if(!factory) throw std::runtime_error{"Failed to get null effect factory"}; al::intrusive_ptr<EffectState> state{factory->create()}; Effect.State = state; diff --git a/al/source.cpp b/al/source.cpp index ea3a4de7..dee4af2a 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -266,7 +266,7 @@ double GetSourceSecOffset(ALsource *Source, ALCcontext *context, nanoseconds *cl BufferFmt = BufferList->mBuffer; ++BufferList; } - assert(BufferFmt != nullptr); + ASSUME(BufferFmt != nullptr); return static_cast<double>(readPos) / double{MixerFracOne} / BufferFmt->mSampleRate; } @@ -315,7 +315,7 @@ double GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) BufferFmt = BufferList->mBuffer; ++BufferList; } - assert(BufferFmt != nullptr); + ASSUME(BufferFmt != nullptr); double offset{}; switch(name) @@ -375,7 +375,7 @@ double GetSourceLength(const ALsource *source, ALenum name) if(length == 0) return 0.0; - assert(BufferFmt != nullptr); + ASSUME(BufferFmt != nullptr); switch(name) { case AL_SEC_LENGTH_SOFT: @@ -585,7 +585,7 @@ bool SetVoiceOffset(Voice *oldvoice, const VoicePos &vpos, ALsource *source, ALC } ++vidx; } - if UNLIKELY(!newvoice) + if(unlikely(!newvoice)) { auto &allvoices = *context->mVoices.load(std::memory_order_relaxed); if(allvoices.size() == voicelist.size()) @@ -605,7 +605,7 @@ bool SetVoiceOffset(Voice *oldvoice, const VoicePos &vpos, ALsource *source, ALC } ++vidx; } - assert(newvoice != nullptr); + ASSUME(newvoice != nullptr); } /* Initialize the new voice and set its starting offset. @@ -3169,7 +3169,7 @@ START_API_FUNC break; } } - assert(voice != nullptr); + ASSUME(voice != nullptr); voice->mPosition.store(0u, std::memory_order_relaxed); voice->mPositionFrac.store(0, std::memory_order_relaxed); diff --git a/core/hrtf.cpp b/core/hrtf.cpp index d94c0569..d4d69815 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -408,7 +408,8 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(uint rate, ushort irSize, auto delays_ = reinterpret_cast<ubyte2*>(base + offset); offset += sizeof(delays_[0])*irCount; - assert(offset == total); + if(unlikely(offset != total)) + throw std::runtime_error{"HrtfStore allocation size mismatch"}; /* Copy input data to storage. */ std::uninitialized_copy(fields.cbegin(), fields.cend(), field_); |