From b5576ccb9f11efcbf1e85e685bcb3b93b113f53f Mon Sep 17 00:00:00 2001 From: SirLynix Date: Mon, 4 Dec 2023 11:01:01 +0100 Subject: [PATCH] Audio: Fix data race when a device is used from multiple threads OpenAL devices can be used from multiple threads and the error handling code (inspired by OpenGLRenderer) did not take that into account. This is not a problem for the OpenGLRenderer since contexts are thread-local which is not the case for OpenAL devices. --- include/Nazara/Audio/OpenALDevice.hpp | 4 ---- include/Nazara/Audio/OpenALDevice.inl | 8 -------- src/Nazara/Audio/OpenALDevice.cpp | 12 ++---------- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/include/Nazara/Audio/OpenALDevice.hpp b/include/Nazara/Audio/OpenALDevice.hpp index a437b5539..ce236b88e 100644 --- a/include/Nazara/Audio/OpenALDevice.hpp +++ b/include/Nazara/Audio/OpenALDevice.hpp @@ -50,8 +50,6 @@ namespace Nz std::shared_ptr CreateBuffer() override; std::shared_ptr CreateSource() override; - inline bool DidLastCallSucceed() const; - float GetDopplerFactor() const override; inline ALFunction GetFunctionByIndex(std::size_t funcIndex) const; float GetGlobalVolume() const override; @@ -106,8 +104,6 @@ namespace Nz OpenALLibrary& m_library; MovablePtr m_context; MovablePtr m_device; - mutable bool m_didCollectErrors; - mutable bool m_hadAnyError; }; } diff --git a/include/Nazara/Audio/OpenALDevice.inl b/include/Nazara/Audio/OpenALDevice.inl index e22f3b30d..7de46c906 100644 --- a/include/Nazara/Audio/OpenALDevice.inl +++ b/include/Nazara/Audio/OpenALDevice.inl @@ -7,14 +7,6 @@ namespace Nz { - inline bool OpenALDevice::DidLastCallSucceed() const - { - if (!m_didCollectErrors) - ProcessErrorFlag(); - - return !m_hadAnyError; - } - inline ALFunction OpenALDevice::GetFunctionByIndex(std::size_t funcIndex) const { assert(funcIndex < m_originalFunctionPointer.size()); diff --git a/src/Nazara/Audio/OpenALDevice.cpp b/src/Nazara/Audio/OpenALDevice.cpp index 44c141963..a19c860f6 100644 --- a/src/Nazara/Audio/OpenALDevice.cpp +++ b/src/Nazara/Audio/OpenALDevice.cpp @@ -178,12 +178,8 @@ namespace Nz NAZARA_USE_ANONYMOUS_NAMESPACE assert(s_currentALDevice == this); - alGetError(); - m_didCollectErrors = false; - m_hadAnyError = false; - return true; } @@ -196,7 +192,7 @@ namespace Nz ALuint bufferId = 0; alGenBuffers(1, &bufferId); - if (!DidLastCallSucceed()) + if (!ProcessErrorFlag()) { NazaraError("failed to create OpenAL buffer"); return {}; @@ -214,7 +210,7 @@ namespace Nz ALuint sourceId = 0; alGenSources(1, &sourceId); - if (!DidLastCallSucceed()) + if (!ProcessErrorFlag()) { NazaraError("failed to create OpenAL buffer"); return {}; @@ -365,7 +361,6 @@ namespace Nz assert(s_currentALDevice == this); bool hasAnyError = false; - if (ALuint lastError = alGetError(); lastError != AL_NO_ERROR) { hasAnyError = true; @@ -373,9 +368,6 @@ namespace Nz NazaraErrorFmt("OpenAL error: {0}", TranslateOpenALError(lastError)); } - m_didCollectErrors = true; - m_hadAnyError = hasAnyError; - return hasAnyError; }