From 976e1e664e67247338ce4c5f1bf5ba1e779573d3 Mon Sep 17 00:00:00 2001 From: Owen Green Date: Sat, 14 Aug 2021 14:38:42 +0100 Subject: [PATCH] SCBufferAdaptor: Strengthen validity and existence concepts --- include/SCBufferAdaptor.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/SCBufferAdaptor.hpp b/include/SCBufferAdaptor.hpp index f3b2a24..e7d3c29 100644 --- a/include/SCBufferAdaptor.hpp +++ b/include/SCBufferAdaptor.hpp @@ -82,14 +82,19 @@ public: bool acquire() const override { return true; } void release() const override {} - // Validity is based on whether this buffer is within the range the server - // knows about + // Validity is reports whether underlying SndBuf is null / 0-size bool valid() const override { - return (mLocal ? true : mBufnum >= 0 && mBufnum < asSigned(mWorld->mNumSndBufs)); + return mBuffer && mBuffer->data && mBuffer->channels && mBuffer->frames; } - bool exists() const override { return true; } + // Existence is based on whether this buffer is within the range the server + // knows about + bool exists() const override + { + return (mLocal ? true + : mBufnum >= 0 && mBufnum < asSigned(mWorld->mNumSndBufs)); + } FluidTensorView allFrames() override { @@ -153,7 +158,7 @@ public: double sampleRate() const override { - return valid() ? mBuffer->samplerate : 0; + return mBuffer ? mBuffer->samplerate : 0; } std::string asString() const override { return std::to_string(bufnum()); }