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.
This commit is contained in:
SirLynix 2023-12-04 11:01:01 +01:00
parent 81c5322331
commit b5576ccb9f
3 changed files with 2 additions and 22 deletions

View File

@ -50,8 +50,6 @@ namespace Nz
std::shared_ptr<AudioBuffer> CreateBuffer() override;
std::shared_ptr<AudioSource> 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<ALCcontext> m_context;
MovablePtr<ALCdevice> m_device;
mutable bool m_didCollectErrors;
mutable bool m_hadAnyError;
};
}

View File

@ -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());

View File

@ -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;
}