Never return null from CreateRingBuffer

Allocation failure would already throw a bad_alloc anyway, now a size overflow
throws an exception too.
This commit is contained in:
Chris Robinson
2019-10-08 21:52:08 -07:00
parent 7726a06d26
commit 963580c2d5
11 changed files with 8 additions and 44 deletions
+4 -17
View File
@@ -521,14 +521,7 @@ bool OpenSLPlayback::reset()
if(SL_RESULT_SUCCESS == result)
{
const ALuint num_updates{mDevice->BufferSize / mDevice->UpdateSize};
try {
mRing = CreateRingBuffer(num_updates, mFrameSize*mDevice->UpdateSize, true);
}
catch(std::exception& e) {
ERR("Failed allocating ring buffer %ux%ux%u: %s\n", mDevice->UpdateSize,
num_updates, mFrameSize, e.what());
result = SL_RESULT_MEMORY_FAILURE;
}
mRing = CreateRingBuffer(num_updates, mFrameSize*mDevice->UpdateSize, true);
}
if(SL_RESULT_SUCCESS != result)
@@ -703,16 +696,10 @@ void OpenSLCapture::open(const ALCchar* name)
mDevice->Frequency/100*5)};
ALuint num_updates{(length+update_len-1) / update_len};
try {
mRing = CreateRingBuffer(num_updates, update_len*mFrameSize, false);
mRing = CreateRingBuffer(num_updates, update_len*mFrameSize, false);
mDevice->UpdateSize = update_len;
mDevice->BufferSize = static_cast<ALuint>(mRing->writeSpace() * update_len);
}
catch(std::exception& e) {
ERR("Failed to allocate ring buffer: %s\n", e.what());
result = SL_RESULT_MEMORY_FAILURE;
}
mDevice->UpdateSize = update_len;
mDevice->BufferSize = static_cast<ALuint>(mRing->writeSpace() * update_len);
}
if(SL_RESULT_SUCCESS == result)
{