# Fmod\_systemi\_thread.cpp(138) - assertion: 'mCrit\[crit\]' failed when trying to migrate user\_created\_sound example to UE

**URL:** https://qa.fmod.com/t/fmod-systemi-thread-cpp-138-assertion-mcrit-crit-failed-when-trying-to-migrate-user-created-sound-example-to-ue/20204
**Category:** Unreal Engine
**Created:** [May 8, 2023, 11:54pm UTC](https://qa.fmod.com/t/fmod-systemi-thread-cpp-138-assertion-mcrit-crit-failed-when-trying-to-migrate-user-created-sound-example-to-ue/20204 "2023-05-08T23:54:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![chrane](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@chrane](https://qa.fmod.com/u/chrane)
#### Post date: [May 8, 2023, 11:54pm UTC](https://qa.fmod.com/t/fmod-systemi-thread-cpp-138-assertion-mcrit-crit-failed-when-trying-to-migrate-user-created-sound-example-to-ue/20204/1 "2023-05-08T23:54:44Z")

</div>

Everything works as expected, except the following error log happens every time exiting the play session.

```auto
LogFMOD: Error: c:\jk\workspace\Build __2.2__ Unreal_Win\core_api\src\fmod_systemi_thread.cpp(65) - assertion: 'mCrit[crit]' failed
LogFMOD: Error: c:\jk\workspace\Build __2.2__ Unreal_Win\core_api\src\fmod_systemi_thread.cpp(138) - assertion: 'mCrit[crit]' failed
LogFMOD: Error: c:\jk\workspace\Build __2.2__ Unreal_Win\core_api\src\fmod_systemi_thread.cpp(65) - assertion: 'mCrit[crit]' failed
LogFMOD: Error: c:\jk\workspace\Build __2.2__ Unreal_Win\core_api\src\fmod_systemi_thread.cpp(138) - assertion: 'mCrit[crit]' failed
LogWorld: UWorld::CleanupWorld for FirstPersonExampleMap, bSessionEnded=true, bCleanupResources=true

```

Code:

```auto
// Fill out your copyright notice in the Description page of Project Settings.

#include "MultiSoundActor.h"

// Sets default values
AMultiSoundActor::AMultiSoundActor()
{
 	// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND* /*sound*/, void* data, unsigned int datalen)
{
	static float t1 = 0, t2 = 0; // time
	static float v1 = 0, v2 = 0; // velocity
	signed short* stereo16bitbuffer = (signed short*)data;

	for (unsigned int count = 0; count < (datalen >> 2); count++) // >>2 = 16bit stereo (4 bytes per sample)
	{
		*stereo16bitbuffer++ = (signed short)(FMath::Sin(t1) * 32767.0f); // left channel
		*stereo16bitbuffer++ = (signed short)(FMath::Sin(t2) * 32767.0f); // right channel

		t1 += 0.01f + v1;
		t2 += 0.0142f + v2;
		v1 += (float)(FMath::Sin(t1) * 0.002f);
		v2 += (float)(FMath::Sin(t2) * 0.002f);
	}

	return FMOD_OK;
}

// Called when the game starts or when spawned
void AMultiSoundActor::BeginPlay()
{
	Super::BeginPlay();
    auto StudioSystem = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);

	

	FMOD::System* system = nullptr;
	StudioSystem->getCoreSystem(&system);
	FMOD_MODE mode = FMOD_OPENUSER | FMOD_LOOP_NORMAL;
	FMOD_CREATESOUNDEXINFO exinfo;
	void* extradriverdata = 0;

	memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
	exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); /* Required. */
	exinfo.numchannels = 2; /* Number of channels in the sound. */
	exinfo.defaultfrequency = 44100; /* Default playback rate of sound. */
	exinfo.decodebuffersize = 44100; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */
	exinfo.length = exinfo.defaultfrequency * exinfo.numchannels * sizeof(signed short) * 5; /* Length of PCM data in bytes of whole song (for Sound::getLength) */
	exinfo.format = FMOD_SOUND_FORMAT_PCM16; /* Data format of sound. */
	exinfo.pcmreadcallback = pcmreadcallback; /* User callback for reading. */

	verifyfmod(system->createSound(0, mode, &exinfo, &sound));

	verifyfmod(system->playSound(sound, 0, 0, &channel));
	

}

// Called every frame
void AMultiSoundActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void AMultiSoundActor::EndPlay(EEndPlayReason::Type Why)
{
	if (channel) 
	{
		channel->stop();
	}
	if (sound) 
	{
		
		sound->release();
	}
}

 

```

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [May 9, 2023, 4:34am UTC](https://qa.fmod.com/t/fmod-systemi-thread-cpp-138-assertion-mcrit-crit-failed-when-trying-to-migrate-user-created-sound-example-to-ue/20204/2 "2023-05-09T04:34:27Z")

</div>

Hi,

What version of FMOD and Unreal are you using?

---

<div class="post-metadata">

### Author: ![chrane](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@chrane](https://qa.fmod.com/u/chrane)
#### Post date: [May 9, 2023, 6:10am UTC](https://qa.fmod.com/t/fmod-systemi-thread-cpp-138-assertion-mcrit-crit-failed-when-trying-to-migrate-user-created-sound-example-to-ue/20204/3 "2023-05-09T06:10:35Z")

</div>

FMOD: 2.02.12  
UE:4.27

Doesn’t seem to affect the program running, but since it’s an assert, figured I should ask.

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [May 10, 2023, 5:24am UTC](https://qa.fmod.com/t/fmod-systemi-thread-cpp-138-assertion-mcrit-crit-failed-when-trying-to-migrate-user-created-sound-example-to-ue/20204/4 "2023-05-10T05:24:28Z")

</div>

Hi,

Thank you for bringing this to our attention and it is definitely worth investigating. I have passed this on to our development team to look into further.
