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:
parent
81c5322331
commit
b5576ccb9f
|
|
@ -50,8 +50,6 @@ namespace Nz
|
||||||
std::shared_ptr<AudioBuffer> CreateBuffer() override;
|
std::shared_ptr<AudioBuffer> CreateBuffer() override;
|
||||||
std::shared_ptr<AudioSource> CreateSource() override;
|
std::shared_ptr<AudioSource> CreateSource() override;
|
||||||
|
|
||||||
inline bool DidLastCallSucceed() const;
|
|
||||||
|
|
||||||
float GetDopplerFactor() const override;
|
float GetDopplerFactor() const override;
|
||||||
inline ALFunction GetFunctionByIndex(std::size_t funcIndex) const;
|
inline ALFunction GetFunctionByIndex(std::size_t funcIndex) const;
|
||||||
float GetGlobalVolume() const override;
|
float GetGlobalVolume() const override;
|
||||||
|
|
@ -106,8 +104,6 @@ namespace Nz
|
||||||
OpenALLibrary& m_library;
|
OpenALLibrary& m_library;
|
||||||
MovablePtr<ALCcontext> m_context;
|
MovablePtr<ALCcontext> m_context;
|
||||||
MovablePtr<ALCdevice> m_device;
|
MovablePtr<ALCdevice> m_device;
|
||||||
mutable bool m_didCollectErrors;
|
|
||||||
mutable bool m_hadAnyError;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,6 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline bool OpenALDevice::DidLastCallSucceed() const
|
|
||||||
{
|
|
||||||
if (!m_didCollectErrors)
|
|
||||||
ProcessErrorFlag();
|
|
||||||
|
|
||||||
return !m_hadAnyError;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline ALFunction OpenALDevice::GetFunctionByIndex(std::size_t funcIndex) const
|
inline ALFunction OpenALDevice::GetFunctionByIndex(std::size_t funcIndex) const
|
||||||
{
|
{
|
||||||
assert(funcIndex < m_originalFunctionPointer.size());
|
assert(funcIndex < m_originalFunctionPointer.size());
|
||||||
|
|
|
||||||
|
|
@ -178,12 +178,8 @@ namespace Nz
|
||||||
NAZARA_USE_ANONYMOUS_NAMESPACE
|
NAZARA_USE_ANONYMOUS_NAMESPACE
|
||||||
|
|
||||||
assert(s_currentALDevice == this);
|
assert(s_currentALDevice == this);
|
||||||
|
|
||||||
alGetError();
|
alGetError();
|
||||||
|
|
||||||
m_didCollectErrors = false;
|
|
||||||
m_hadAnyError = false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,7 +192,7 @@ namespace Nz
|
||||||
ALuint bufferId = 0;
|
ALuint bufferId = 0;
|
||||||
alGenBuffers(1, &bufferId);
|
alGenBuffers(1, &bufferId);
|
||||||
|
|
||||||
if (!DidLastCallSucceed())
|
if (!ProcessErrorFlag())
|
||||||
{
|
{
|
||||||
NazaraError("failed to create OpenAL buffer");
|
NazaraError("failed to create OpenAL buffer");
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -214,7 +210,7 @@ namespace Nz
|
||||||
ALuint sourceId = 0;
|
ALuint sourceId = 0;
|
||||||
alGenSources(1, &sourceId);
|
alGenSources(1, &sourceId);
|
||||||
|
|
||||||
if (!DidLastCallSucceed())
|
if (!ProcessErrorFlag())
|
||||||
{
|
{
|
||||||
NazaraError("failed to create OpenAL buffer");
|
NazaraError("failed to create OpenAL buffer");
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -365,7 +361,6 @@ namespace Nz
|
||||||
assert(s_currentALDevice == this);
|
assert(s_currentALDevice == this);
|
||||||
|
|
||||||
bool hasAnyError = false;
|
bool hasAnyError = false;
|
||||||
|
|
||||||
if (ALuint lastError = alGetError(); lastError != AL_NO_ERROR)
|
if (ALuint lastError = alGetError(); lastError != AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
hasAnyError = true;
|
hasAnyError = true;
|
||||||
|
|
@ -373,9 +368,6 @@ namespace Nz
|
||||||
NazaraErrorFmt("OpenAL error: {0}", TranslateOpenALError(lastError));
|
NazaraErrorFmt("OpenAL error: {0}", TranslateOpenALError(lastError));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_didCollectErrors = true;
|
|
||||||
m_hadAnyError = hasAnyError;
|
|
||||||
|
|
||||||
return hasAnyError;
|
return hasAnyError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue