From a237102de9913f008a170fc347ccbeb8ae71975e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Tue, 7 Jun 2022 22:47:54 +0200 Subject: [PATCH] Music: fix concurrent access on destruction --- src/Nazara/Audio/Music.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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) {