PlayQuantized is crashing / ensuring fires when I queue from another delegate

I’m trying to set up a system where a quartz clock delegate queues up audio at the beginning of each bar. Unfortunately at three audio cues the whole editor crashes with a stacktrace in UnrealCore malloc calls.

Instead of pasting code, I created a repo of an example crash: playquantized_example/QuartzCrash/Source/QuartzCrash/Private at main · andriustheviking/playquantized_example · GitHub

Here’s the stack trace:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffffffffffff

0x00007fff907d981b UnrealEditor-Core.dll!mi_free() [D:\build\++UE5\Sync\Engine\Source\ThirdParty\mimalloc\2.0.0\src\alloc.c:486]
0x00007fff9014ea3d UnrealEditor-Core.dll!FMallocMimalloc::Realloc() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\HAL\MallocMimalloc.cpp:155]
0x00007fff9014ef33 UnrealEditor-Core.dll!FMemory::Realloc() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\HAL\FMemory.inl:118]
0x00007fff90013328 UnrealEditor-Core.dll!TSizedHeapAllocator<32,FMemory>::ForAnyElementType::ResizeAllocation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\ContainerAllocationPolicies.h:725]
0x00007fff8b86b24c UnrealEditor-Engine.dll!TArray<TScriptDelegate<FNotThreadSafeNotCheckedDelegateMode>,TSizedDefaultAllocator<32> >::ResizeTo() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\Array.h:3143]
0x00007fff8b85a291 UnrealEditor-Engine.dll!FQuartzTickableObject::ExecCommand() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Classes\Sound\QuartzSubscription.cpp:122]
0x00007fff8b838c49 UnrealEditor-Engine.dll!UE::TConsumeAllMpmcQueue<TFunction<void __cdecl(FQuartzTickableObject * __ptr64)>,FMemory>::ConsumeAll<1,`Audio::TQuartzShareableCommandQueue<FQuartzTickableObject>::PumpCommandQueue'::`2'::<lambda_1> >() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\ConsumeAllMpmcQueue.h:119]
0x00007fff8b865bf0 UnrealEditor-Engine.dll!FQuartzTickableObject::QuartzTick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Classes\Sound\QuartzSubscription.cpp:180]
0x00007fffac9535c4 UnrealEditor-AudioMixer.dll!FQuartzTickableObjectsManager::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\AudioMixer\Private\Quartz\QuartzSubsystem.cpp:111]
0x00007fffac953876 UnrealEditor-AudioMixer.dll!UQuartzSubsystem::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\AudioMixer\Private\Quartz\QuartzSubsystem.cpp:208]
0x00007fff8dbbb022 UnrealEditor-Engine.dll!FTickableGameObject::TickObjects() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Tickable.cpp:153]
0x00007fff8ca4f681 UnrealEditor-Engine.dll!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1568]
0x00007fff8c68ad38 UnrealEditor-Engine.dll!UGameEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\GameEngine.cpp:1785]
0x00007ff724ea8e0b UnrealEditor.exe!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5921]
0x00007ff724ece33c UnrealEditor.exe!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:180]
0x00007ff724ece42a UnrealEditor.exe!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:118]
0x00007ff724ed18a4 UnrealEditor.exe!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:258]
0x00007ff724ee70c4 UnrealEditor.exe!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:298]
0x00007ff724eea37a UnrealEditor.exe!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
0x00007ff8dacbe8d7 KERNEL32.DLL!UnknownFunction []

I don’t think it’s just an Editor issue, as I hit the following ensure in standalone:

[2025.03.26-00.34.23:632][402]LogOutputDevice: Error: === Handled ensure: ===
[2025.03.26-00.34.23:632][402]LogOutputDevice: Error: 
[2025.03.26-00.34.23:632][402]LogOutputDevice: Error: Ensure condition failed: ReaderIndex != INDEX_NONE  [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Misc\MTAccessDetector.h] [Line: 568] 
[2025.03.26-00.34.23:632][402]LogOutputDevice: Error: Either a race detected (58240 reader(s) on another thread(s) while acquiring write access on the current thread) or the access detector was trivially relocated:
[2025.03.26-00.34.23:632][402]LogOutputDevice: Error: Current thread 10584 callstack:
[2025.03.26-00.34.23:632][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b64e837 UnrealEditor-Engine.dll!FMRSWRecursiveAccessDetector::GetCurrentThreadCallstack() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Misc\MTAccessDetector.h:368]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fff8e30a3b9 UnrealEditor-Engine.dll!`FMRSWRecursiveAccessDetector::AcquireWriteAccess'::`5'::<lambda_2>::operator()() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Misc\MTAccessDetector.h:568]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b645b5d UnrealEditor-Engine.dll!TDelegateAccessHandlerBase<FNotThreadSafeDelegateMode>::FWriteAccessScope::FWriteAccessScope() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateAccessHandler.h:139]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b85a27c UnrealEditor-Engine.dll!FQuartzTickableObject::ExecCommand() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Classes\Sound\QuartzSubscription.cpp:122]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b838c49 UnrealEditor-Engine.dll!UE::TConsumeAllMpmcQueue<TFunction<void __cdecl(FQuartzTickableObject * __ptr64)>,FMemory>::ConsumeAll<1,`Audio::TQuartzShareableCommandQueue<FQuartzTickableObject>::PumpCommandQueue'::`2'::<lambda_1> >() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\ConsumeAllMpmcQueue.h:119]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b865bf0 UnrealEditor-Engine.dll!FQuartzTickableObject::QuartzTick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Classes\Sound\QuartzSubscription.cpp:180]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fffac9535c4 UnrealEditor-AudioMixer.dll!FQuartzTickableObjectsManager::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\AudioMixer\Private\Quartz\QuartzSubsystem.cpp:111]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fffac953876 UnrealEditor-AudioMixer.dll!UQuartzSubsystem::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\AudioMixer\Private\Quartz\QuartzSubsystem.cpp:208]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fff8dbbb022 UnrealEditor-Engine.dll!FTickableGameObject::TickObjects() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Tickable.cpp:153]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fff8ca4f681 UnrealEditor-Engine.dll!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1568]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007fff8c68ad38 UnrealEditor-Engine.dll!UGameEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\GameEngine.cpp:1785]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ea8e0b UnrealEditor.exe!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5921]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ece33c UnrealEditor.exe!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:180]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ece42a UnrealEditor.exe!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:118]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ed18a4 UnrealEditor.exe!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:258]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ee70c4 UnrealEditor.exe!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:298]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007ff724eea37a UnrealEditor.exe!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007ff8dacbe8d7 KERNEL32.DLL!UnknownFunction []
[2025.03.26-00.34.23:633][402]LogOutputDevice: Error: [Callstack] 0x00007ff8dbb3bf6c ntdll.dll!UnknownFunction []
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: 
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: Stack: 
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fff8e30a404 UnrealEditor-Engine.dll!`FMRSWRecursiveAccessDetector::AcquireWriteAccess'::`5'::<lambda_2>::operator()() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Misc\MTAccessDetector.h:568]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b645b5d UnrealEditor-Engine.dll!TDelegateAccessHandlerBase<FNotThreadSafeDelegateMode>::FWriteAccessScope::FWriteAccessScope() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateAccessHandler.h:139]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b85a27c UnrealEditor-Engine.dll!FQuartzTickableObject::ExecCommand() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Classes\Sound\QuartzSubscription.cpp:122]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b838c49 UnrealEditor-Engine.dll!UE::TConsumeAllMpmcQueue<TFunction<void __cdecl(FQuartzTickableObject * __ptr64)>,FMemory>::ConsumeAll<1,`Audio::TQuartzShareableCommandQueue<FQuartzTickableObject>::PumpCommandQueue'::`2'::<lambda_1> >() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\ConsumeAllMpmcQueue.h:119]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fff8b865bf0 UnrealEditor-Engine.dll!FQuartzTickableObject::QuartzTick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Classes\Sound\QuartzSubscription.cpp:180]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fffac9535c4 UnrealEditor-AudioMixer.dll!FQuartzTickableObjectsManager::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\AudioMixer\Private\Quartz\QuartzSubsystem.cpp:111]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fffac953876 UnrealEditor-AudioMixer.dll!UQuartzSubsystem::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\AudioMixer\Private\Quartz\QuartzSubsystem.cpp:208]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fff8dbbb022 UnrealEditor-Engine.dll!FTickableGameObject::TickObjects() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Tickable.cpp:153]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fff8ca4f681 UnrealEditor-Engine.dll!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1568]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007fff8c68ad38 UnrealEditor-Engine.dll!UGameEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\GameEngine.cpp:1785]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ea8e0b UnrealEditor.exe!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5921]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ece33c UnrealEditor.exe!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:180]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ece42a UnrealEditor.exe!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:118]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ed18a4 UnrealEditor.exe!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:258]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007ff724ee70c4 UnrealEditor.exe!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:298]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007ff724eea37a UnrealEditor.exe!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007ff8dacbe8d7 KERNEL32.DLL!UnknownFunction []
[2025.03.26-00.34.23:634][402]LogOutputDevice: Error: [Callstack] 0x00007ff8dbb3bf6c ntdll.dll!UnknownFunction []

After a lot of trial and error, the underlying issue appears to be that I was passing the same UQuartzClockHandle around from object to object. That made the underlying system very confused.

It seems each object that registers delegates with the quartz clock needs to (implicitly) fetch its own handle via call to UQuartzSubsystem::GetHandleForClock(const UObject* WorldContextObject, FName ClockName).

So moral of the story, is DON’T pass the quartz handle, only pass the Name and fetch the handle indirectly.

At least for now…