Audio/Music: Fix possible data-race in GetPlayingOffset

This commit is contained in:
Lynix 2023-11-29 22:26:19 +01:00
parent ad81b8642e
commit 150787971a
1 changed files with 3 additions and 3 deletions

View File

@ -131,12 +131,12 @@ namespace Nz
{
NazaraAssert(m_stream, "Music not created");
if (!m_streaming)
return Time::Zero();
// Prevent music thread from enqueuing new buffers while we're getting the count
std::lock_guard<std::recursive_mutex> lock(m_sourceLock);
if (!m_streaming)
return Time::Zero();
Time playingOffset = m_source->GetPlayingOffset();
Time processedTime = Time::Microseconds(1'000'000ll * m_processedSamples / (GetChannelCount(m_stream->GetFormat()) * m_sampleRate));
playingOffset += processedTime;