diff options
author | Chris Robinson <[email protected]> | 2019-09-15 13:42:56 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-09-15 13:42:56 -0700 |
commit | 35129d66b78c146266cd85da68c5725fc289e49a (patch) | |
tree | 8d0609056f5930435fd93537e4ae8a3bc98d8f6f | |
parent | a999df8ce5f3a2c5bdbe99cebea47a56d2bf1f66 (diff) |
Clean up the spaghetti mess in alcCaptureSamples
-rw-r--r-- | alc/alc.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp index 4a4ed677..a5fde792 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -3907,14 +3907,26 @@ START_API_FUNC return; } - ALCenum err{ALC_INVALID_VALUE}; - { std::lock_guard<std::mutex> _{dev->StateLock}; - BackendBase *backend{dev->Backend.get()}; - if(samples >= 0 && backend->availableSamples() >= static_cast<ALCuint>(samples)) - err = backend->captureSamples(static_cast<al::byte*>(buffer), - static_cast<ALuint>(samples)); + if(samples < 0 || (samples > 0 && buffer == nullptr)) + { + alcSetError(dev.get(), ALC_INVALID_VALUE); + return; } - if(err != ALC_NO_ERROR) + if(samples < 1) + return; + + std::lock_guard<std::mutex> _{dev->StateLock}; + BackendBase *backend{dev->Backend.get()}; + + const auto usamples = static_cast<ALCuint>(samples); + if(usamples > backend->availableSamples()) + { + alcSetError(dev.get(), ALC_INVALID_VALUE); + return; + } + + auto *bbuffer = static_cast<al::byte*>(buffer); + if(ALCenum err{backend->captureSamples(bbuffer, usamples)}) alcSetError(dev.get(), err); } END_API_FUNC |