diff --git a/src/Nazara/Audio/Music.cpp b/src/Nazara/Audio/Music.cpp index fc6e0b46e..1291e980e 100644 --- a/src/Nazara/Audio/Music.cpp +++ b/src/Nazara/Audio/Music.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include 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> 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) {