Music: fix concurrent access on destruction

This commit is contained in:
Jérôme Leclercq 2022-06-07 22:47:54 +02:00 committed by GitHub
parent 916fecbf37
commit a237102de9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -12,6 +12,7 @@
#include <Nazara/Utils/CallOnExit.hpp>
#include <array>
#include <chrono>
#include <optional>
#include <Nazara/Audio/Debug.hpp>
namespace Nz
@ -397,6 +398,8 @@ namespace Nz
void Music::MusicThread(std::condition_variable& cv, std::mutex& m, std::exception_ptr& err, bool startPaused)
{
std::optional<std::lock_guard<std::recursive_mutex>> exitLock;
// Allocation of streaming buffers
CallOnExit unqueueBuffers([&]
{
@ -442,6 +445,12 @@ namespace Nz
cv.notify_all();
} // m & cv no longer exists from here
// From now, the source can be accessed from another thread, lock it before others destructors
CallOnExit lockSource([&]
{
exitLock.emplace(m_sourceLock);
});
// Reading loop (Filling new buffers as playing)
while (m_streaming)
{