Fix audio clips streaming to be thread-safe when audio sources play

#786
This commit is contained in:
Wojtek Figat
2022-10-29 18:57:57 +02:00
parent 6379171fa6
commit 57e812d336
4 changed files with 10 additions and 5 deletions

View File

@@ -20,10 +20,11 @@ bool AudioClip::StreamingTask::Run()
{
AssetReference<AudioClip> ref = _asset.Get();
if (ref == nullptr)
{
return true;
}
ScopeLock lock(ref->Locker);
const auto& queue = ref->StreamingQueue;
if (queue.Count() == 0)
return false;
auto clip = ref.Get();
// Update the buffers
@@ -108,7 +109,6 @@ bool AudioClip::StreamingTask::Run()
for (int32 sourceIndex = 0; sourceIndex < Audio::Sources.Count(); sourceIndex++)
{
// TODO: collect refs to audio clip from sources and use faster iteration (but do it thread-safe)
const auto src = Audio::Sources[sourceIndex];
if (src->Clip == clip && src->GetState() == AudioSource::States::Playing)
{