MediaSoundWave's QueuedAudio crash

In MediaSoundWave.cpp,

int32 UMediaSoundWave::GeneratePCMData(uint8* Data, const int32 SamplesRequested)
{
	if ((Data == nullptr) || (SamplesRequested <= 0))
	{
		return 0;
	}

	// return queued samples
	if (!Paused && (SinkNumChannels > 0) && (SinkSampleRate > 0) && (QueuedAudio.Num() > 0))
	{
		FScopeLock Lock(&CriticalSection);

QueuedAudio.Num() can change (by flushing by example) before it’s locked. This causes crashes as [0] is accessed immediately afterwards.

Consider putting the QueuedAudio check immediately after the lock instead.

	// return queued samples
	if (!Paused && (SinkNumChannels > 0) && (SinkSampleRate > 0))
	{
		FScopeLock Lock(&CriticalSection);

		if (QueuedAudio.Num() > 0)
		{

Hey -

Can you provide an example of what causes the crash you mentioned as well as the callstack and log files from the crash? What are you doing to flush QueuedAudio?

, I am sorry I only got that crash once by chance. I didn’t save much data on it as I was looking for something else. I’d guess I was horrendously (un)lucky to get that crash.

What I had was this line (#50) crashing:

			FMemory::Memcpy((void*)Data, &QueuedAudio[0], BytesToCopy);

and QueuedAudio was Empty (not paused, SinkNumChannels = 2, SinkSampleRate = 48000). Because QueuedAudio.Num() is specifically checked just before, I assumed this was a misplaced lock. After checking, I could confirm QueuedAudio is locked every single time it’s modified, but in here, it’s being polled without being locked.

This happened immediately after stopping a m4v video from playing using the Pause command.

How are you using your m4v file in the editor? Can you list the steps used in your setup to help me test the issue locally? Are you pausing the video or the entire game?

Hey -

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will follow up.

Cheers