Thread Safety for Event Dispatcher broadcasting using AsyncTask

I’m trying to call event dispatchers from game thread using Async Task, the function calls are on other threads. Not all the times but there are crashes on android devices here is the code and the log error

TArray<FString> Result = JavaConvert::ConvertToStringArray(result);

// to prevent the Result from being null when asynctask is operating move is used
AsyncTask(ENamedThreads::Type::GameThread, [LocalResult = MoveTemp(Result)] ()
{
	if (!IsInGameThread())
	{
		UE_LOG(LogTemp, Error, TEXT("Attempted to broadcast delegate from wrong thread!"));
		return;
	}

	if (CallbackObj->IsValid() && CallbackObj->GetFilePickerResultDelegate().IsBound())
	{
		CallbackObj->GetFilePickerResultDelegate().Broadcast(LocalResult);
	}
});

and here is the log

[2025.05.04-14.03.03:762][863]LogStats: FPlatformStackWalk::StackWalkAndDump -  0.082 s
[2025.05.04-14.03.03:763][863]LogOutputDevice: Error: === Handled ensure: ===
[2025.05.04-14.03.03:763][863]LogOutputDevice: Error: 
[2025.05.04-14.03.03:763][863]LogOutputDevice: Error: Ensure condition failed: InState.GetWriterThreadId() == CurrentThreadId  [File:Runtime/Core/Public/Misc/MTAccessDetector.h] [Line: 359] 
[2025.05.04-14.03.03:763][863]LogOutputDevice: Error: Data race detected! Acquiring read access on thread 18725 concurrently with 3549 writers on thread 3722304988:
[2025.05.04-14.03.03:763][863]LogOutputDevice: Error: Current thread 18725 callstack:
[2025.05.04-14.03.03:764][863]LogOutputDevice: Error: [Callstack] 0x0000007D927FC8C8 libUnreal.so(0x00000000097FB8C8)!FMRSWRecursiveAccessDetector::CheckOtherThreadWriters(FMRSWRecursiveAccessDetector::FState)::{lambda()#1}::operator()() const  []
[2025.05.04-14.03.03:764][863]LogOutputDevice: Error: [Callstack] 0x0000007D927FC69C libUnreal.so(0x00000000097FB69C)!TDelegateAccessHandlerBase<FNotThreadSafeDelegateMode>::FReadAccessScope::FReadAccessScope(FMRSWRecursiveAccessDetector const&)  []
[2025.05.04-14.03.03:764][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A5C01C0 libUnreal.so(0x00000000115BF1C0)!TMulticastScriptDelegate<FNotThreadSafeDelegateMode>::TMulticastScriptDelegate(TMulticastScriptDelegate<FNotThreadSafeDelegateMode> const&)  []
[2025.05.04-14.03.03:764][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A5C73F8 libUnreal.so(0x00000000115C63F8)![Unknown]()  []
[2025.05.04-14.03.03:764][863]LogOutputDevice: Error: [Callstack] 0x0000007D9281214C libUnreal.so(0x000000000981114C)!TGraphTask<FAsyncGraphTask>::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type, bool)  []
[2025.05.04-14.03.03:764][863]LogOutputDevice: Error: [Callstack] 0x0000007D92804F68 libUnreal.so(0x0000000009803F68)!FNamedTaskThread::ProcessTasksNamedThread(int, bool)  []
[2025.05.04-14.03.03:764][863]LogOutputDevice: Error: [Callstack] 0x0000007D92803550 libUnreal.so(0x0000000009802550)!FNamedTaskThread::ProcessTasksUntilIdle(int)  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9470F754 libUnreal.so(0x000000000B70E754)!FRenderCommandFence::Wait(bool) const  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A13879C libUnreal.so(0x000000001113779C)!FEngineLoop::Tick()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A12C580 libUnreal.so(0x000000001112B580)!AndroidMain(android_app*)  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A13CA60 libUnreal.so(0x000000001113BA60)!android_main()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A163BC8 libUnreal.so(0x0000000011162BC8)![Unknown]()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007F5C959D10 libc.so(0x0000000000101D10)![Unknown]()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007F5C8EDAE4 libc.so(0x0000000000095AE4)![Unknown]()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: 
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: Writer thread 3722304988 callstack:
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: 
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: Stack: 
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D927FC974 libUnreal.so(0x00000000097FB974)!FMRSWRecursiveAccessDetector::CheckOtherThreadWriters(FMRSWRecursiveAccessDetector::FState)::{lambda()#1}::operator()() const  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D927FC69C libUnreal.so(0x00000000097FB69C)!TDelegateAccessHandlerBase<FNotThreadSafeDelegateMode>::FReadAccessScope::FReadAccessScope(FMRSWRecursiveAccessDetector const&)  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A5C01C0 libUnreal.so(0x00000000115BF1C0)!TMulticastScriptDelegate<FNotThreadSafeDelegateMode>::TMulticastScriptDelegate(TMulticastScriptDelegate<FNotThreadSafeDelegateMode> const&)  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A5C73F8 libUnreal.so(0x00000000115C63F8)![Unknown]()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9281214C libUnreal.so(0x000000000981114C)!TGraphTask<FAsyncGraphTask>::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type, bool)  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D92804F68 libUnreal.so(0x0000000009803F68)!FNamedTaskThread::ProcessTasksNamedThread(int, bool)  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D92803550 libUnreal.so(0x0000000009802550)!FNamedTaskThread::ProcessTasksUntilIdle(int)  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9470F754 libUnreal.so(0x000000000B70E754)!FRenderCommandFence::Wait(bool) const  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A13879C libUnreal.so(0x000000001113779C)!FEngineLoop::Tick()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A12C580 libUnreal.so(0x000000001112B580)!AndroidMain(android_app*)  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A13CA60 libUnreal.so(0x000000001113BA60)!android_main()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007D9A163BC8 libUnreal.so(0x0000000011162BC8)![Unknown]()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007F5C959D10 libc.so(0x0000000000101D10)![Unknown]()  []
[2025.05.04-14.03.03:765][863]LogOutputDevice: Error: [Callstack] 0x0000007F5C8EDAE4 libc.so(0x0000000000095AE4)![Unknown]()  []
[2025.05.04-14.03.03:766][863]LogOutputDevice: Error: 

i think that’s the problem.

you surely know that this means that the following code is on another thread.
the print then creates a race condition with the output device (the console)

it’s mostly a guess, but seems reasonable since the error comes from the outputdevice.
i can’t remember if you can or can’t use logs on bg threads, since i never did, but makes sense it’s not threadsafe.
i would expect though some kind of flag to make it threadsafe.

though it’s pretty weird that condition is hit, since you specify the asynctask to run on game thread. which “should never happen” :trade_mark:.

yeah your right it shouldn’t hit and honestly never seen it happening anywhere I will remove it and update you later on.
Thanks.

Nope it seem like that’s not the main problem this time I used AFS to get and check log files and found out I didn’t get the all logs this one is the complete error log
seems like a segfault and race condition

05-05 10:01:08.228  5517  5978 D UE      :
05-05 10:01:08.228  5517  5978 D UE      : Script Stack (0 frames) :
05-05 10:01:08.228  5517  5978 D UE      :
05-05 10:01:08.228  5517  5978 D UE      : Ensure condition failed: InState.GetWriterThreadId() == CurrentThreadId [File:Runtime/Core/Public/Misc/MTAccessDetector.h] [Line: 359]
05-05 10:01:08.228  5517  5978 D UE      : Data race detected! Acquiring read access on thread 5978 concurrently with 3549 writers on thread 3722304988:
05-05 10:01:08.228  5517  5978 D UE      : Current thread 5978 callstack:
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A3260C8C8 libUnreal.so(0x00000000097FB8C8)!FMRSWRecursiveAccessDetector::CheckOtherThreadWriters(FMRSWRecursiveAccessDetector::FState)::{lambda()#1}::operator()() const  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A3260C69C libUnreal.so(0x00000000097FB69C)!TDelegateAccessHandlerBase<FNotThreadSafeDelegateMode>::FReadAccessScope::FReadAccessScope(FMRSWRecursiveAccessDetector const&)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A3A3D0294 libUnreal.so(0x00000000115BF294)!TMulticastScriptDelegate<FNotThreadSafeDelegateMode>::TMulticastScriptDelegate(TMulticastScriptDelegate<FNotThreadSafeDelegateMode> const&)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A3A3D7418 libUnreal.so(0x00000000115C6418)![Unknown]()  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A3262214C libUnreal.so(0x000000000981114C)!TGraphTask<FAsyncGraphTask>::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type, bool)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A32614F68 libUnreal.so(0x0000000009803F68)!FNamedTaskThread::ProcessTasksNamedThread(int, bool)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A3261340C libUnreal.so(0x000000000980240C)!FNamedTaskThread::ProcessTasksUntilQuit(int)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A32612340 libUnreal.so(0x0000000009801340)!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete(TArray<TRefCountPtr<FGraphEvent>, TSizedInlineAllocator<4u, 32, TSizedDefaultAllocator<32> > > const&, ENamedThreads::Type)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A394B8178 libUnreal.so(0x00000000106A7178)!FTickTaskSequencer::ReleaseTickGroup(ETickingGroup, bool)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A394B313C libUnreal.so(0x00000000106A213C)!FTickTaskManager::RunTickGroup(ETickingGroup, bool)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A388B42BC libUnreal.so(0x000000000FAA32BC)!UWorld::Tick(ELevelTick, float)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A385B8B20 libUnreal.so(0x000000000F7A7B20)!UGameEngine::Tick(float, bool)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A39F44C88 libUnreal.so(0x0000000011133C88)!FEngineLoop::Tick()  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A39F3C580 libUnreal.so(0x000000001112B580)!AndroidMain(android_app*)  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A39F4CA60 libUnreal.so(0x000000001113BA60)!android_main()  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007A39F73BC8 libUnreal.so(0x0000000011162BC8)![Unknown]()  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007C2C502D60 libc.so(0x0000000000101D60)![Unknown]()  []
05-05 10:01:08.228  5517  5978 D UE      : 0x0000007C2C496BC4 libc.so(0x0000000000095BC4)![Unknown]()  []
05-05 10:01:08.228  5517  5978 D UE      :
05-05 10:01:08.228  5517  5978 D UE      : Writer thread 3722304988 callstack:
05-05 10:01:08.228  5517  5978 D UE      :
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogStats: FPlatformStackWalk::StackWalkAndDump -  0.076 s
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: === Handled ensure: ===
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error:
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: Ensure condition failed: InState.GetWriterThreadId() == CurrentThreadId  [File:Runtime/Core/Public/Misc/MTAccessDetector.h] [Line: 359]
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: Data race detected! Acquiring read access on thread 5978 concurrently with 3549 writers on thread 3722304988:
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: Current thread 5978 callstack:
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3260C8C8 libUnreal.so(0x00000000097FB8C8)!FMRSWRecursiveAccessDetector::CheckOtherThreadWriters(FMRSWRecursiveAccessDetector::FState)::{lambda()#1}::operator()() const  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3260C69C libUnreal.so(0x00000000097FB69C)!TDelegateAccessHandlerBase<FNotThreadSafeDelegateMode>::FReadAccessScope::FReadAccessScope(FMRSWRecursiveAccessDetector const&)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3A3D0294 libUnreal.so(0x00000000115BF294)!TMulticastScriptDelegate<FNotThreadSafeDelegateMode>::TMulticastScriptDelegate(TMulticastScriptDelegate<FNotThreadSafeDelegateMode> const&)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3A3D7418 libUnreal.so(0x00000000115C6418)![Unknown]()  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3262214C libUnreal.so(0x000000000981114C)!TGraphTask<FAsyncGraphTask>::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type, bool)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A32614F68 libUnreal.so(0x0000000009803F68)!FNamedTaskThread::ProcessTasksNamedThread(int, bool)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3261340C libUnreal.so(0x000000000980240C)!FNamedTaskThread::ProcessTasksUntilQuit(int)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A32612340 libUnreal.so(0x0000000009801340)!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete(TArray<TRefCountPtr<FGraphEvent>, TSizedInlineAllocator<4u, 32, TSizedDefaultAllocator<32> > > const&, ENamedThreads::Type)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A394B8178 libUnreal.so(0x00000000106A7178)!FTickTaskSequencer::ReleaseTickGroup(ETickingGroup, bool)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A394B313C libUnreal.so(0x00000000106A213C)!FTickTaskManager::RunTickGroup(ETickingGroup, bool)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A388B42BC libUnreal.so(0x000000000FAA32BC)!UWorld::Tick(ELevelTick, float)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A385B8B20 libUnreal.so(0x000000000F7A7B20)!UGameEngine::Tick(float, bool)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A39F44C88 libUnreal.so(0x0000000011133C88)!FEngineLoop::Tick()  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A39F3C580 libUnreal.so(0x000000001112B580)!AndroidMain(android_app*)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A39F4CA60 libUnreal.so(0x000000001113BA60)!android_main()  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A39F73BC8 libUnreal.so(0x0000000011162BC8)![Unknown]()  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007C2C502D60 libc.so(0x0000000000101D60)![Unknown]()  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007C2C496BC4 libc.so(0x0000000000095BC4)![Unknown]()  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error:
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: Writer thread 3722304988 callstack:
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error:
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: Stack:
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3260C974 libUnreal.so(0x00000000097FB974)!FMRSWRecursiveAccessDetector::CheckOtherThreadWriters(FMRSWRecursiveAccessDetector::FState)::{lambda()#1}::operator()() const  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3260C69C libUnreal.so(0x00000000097FB69C)!TDelegateAccessHandlerBase<FNotThreadSafeDelegateMode>::FReadAccessScope::FReadAccessScope(FMRSWRecursiveAccessDetector const&)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3A3D0294 libUnreal.so(0x00000000115BF294)!TMulticastScriptDelegate<FNotThreadSafeDelegateMode>::TMulticastScriptDelegate(TMulticastScriptDelegate<FNotThreadSafeDelegateMode> const&)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3A3D7418 libUnreal.so(0x00000000115C6418)![Unknown]()  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3262214C libUnreal.so(0x000000000981114C)!TGraphTask<FAsyncGraphTask>::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type, bool)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A32614F68 libUnreal.so(0x0000000009803F68)!FNamedTaskThread::ProcessTasksNamedThread(int, bool)  []
05-05 10:01:08.305  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A3261340C libUnreal.so(0x000000000980240C)!FNamedTaskThread::ProcessTasksUntilQuit(int)  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:305][607]LogOutputDevice: Error: [Callstack] 0x0000007A32612340 libUnreal.so(0x0000000009801340)!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete(TArray<TRefCountPtr<FGraphEvent>, TSizedInlineAllocator<4u, 32, TSizedDefaultAllocator<32> > > const&, ENamedThreads::Type)  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007A394B8178 libUnreal.so(0x00000000106A7178)!FTickTaskSequencer::ReleaseTickGroup(ETickingGroup, bool)  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007A394B313C libUnreal.so(0x00000000106A213C)!FTickTaskManager::RunTickGroup(ETickingGroup, bool)  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007A388B42BC libUnreal.so(0x000000000FAA32BC)!UWorld::Tick(ELevelTick, float)  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007A385B8B20 libUnreal.so(0x000000000F7A7B20)!UGameEngine::Tick(float, bool)  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007A39F44C88 libUnreal.so(0x0000000011133C88)!FEngineLoop::Tick()  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007A39F3C580 libUnreal.so(0x000000001112B580)!AndroidMain(android_app*)  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007A39F4CA60 libUnreal.so(0x000000001113BA60)!android_main()  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007A39F73BC8 libUnreal.so(0x0000000011162BC8)![Unknown]()  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007C2C502D60 libc.so(0x0000000000101D60)![Unknown]()  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error: [Callstack] 0x0000007C2C496BC4 libc.so(0x0000000000095BC4)![Unknown]()  []
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogOutputDevice: Error:
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogStats:                SubmitErrorReport -  0.000 s
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogStats:                    SendNewReport -  0.000 s
05-05 10:01:08.306  5517  5978 D UE      : [2025.05.05-06.31.08:306][607]LogStats:             FDebug::EnsureFailed -  0.078 s
05-05 10:01:08.927  5517  5983 D UE      : [GameActivity] --- memstats:
05-05 10:01:08.927  5517  5983 D UE      : memstat: Used memory: 205498
05-05 10:01:08.927  5517  5983 D UE      : memstat: VmSize:	10598760 kB
05-05 10:01:08.927  5517  5983 D UE      : memstat: VmHWM:	  913992 kB
05-05 10:01:08.927  5517  5983 D UE      : memstat: VmRSS:	  841024 kB
05-05 10:01:08.927  5517  5983 D UE      : memstat: VmData:	 3541400 kB
05-05 10:01:08.927  5517  5983 D UE      : memstat: VmSwap:	   23660 kB
--------- beginning of crash
05-05 10:01:09.719  7663  7663 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-05 10:01:09.719  7663  7663 F DEBUG   : Build fingerprint: 'Redmi/tanzanite_global/tanzanite:14/UP1A.231005.007/V816.0.7.0.UOGMIXM:user/release-keys'
05-05 10:01:09.719  7663  7663 F DEBUG   : Revision: '0'
05-05 10:01:09.719  7663  7663 F DEBUG   : ABI: 'arm64'
05-05 10:01:09.719  7663  7663 F DEBUG   : Timestamp: 2025-05-05 10:01:08.495101679+0330
05-05 10:01:09.719  7663  7663 F DEBUG   : Process uptime: 93s
05-05 10:01:09.719  7663  7663 F DEBUG   : Cmdline: com.a.ar
05-05 10:01:09.719  7663  7663 F DEBUG   : pid: 5517, tid: 5978, name: GameThread  >>>  <<<
05-05 10:01:09.719  7663  7663 F DEBUG   : uid: 10344
05-05 10:01:09.719  7663  7663 F DEBUG   : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
05-05 10:01:09.719  7663  7663 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000000
05-05 10:01:09.719  7663  7663 F DEBUG   : Cause: null pointer dereference
05-05 10:01:09.719  7663  7663 F DEBUG   :     x0  fffffffddddde000  x1  fffffffdddddddd0  x2  0000000000000004  x3  0000007a3261f840
05-05 10:01:09.719  7663  7663 F DEBUG   :     x4  0000007a226cbbc0  x5  0000007c3eac0e88  x6  6e00000000000000  x7  000000000000006e
05-05 10:01:09.719  7663  7663 F DEBUG   :     x8  0000000000000000  x9  0fffffffddddde00  x10 fffffffdddddedcf  x11 0000000000000001
05-05 10:01:09.719  7663  7663 F DEBUG   :     x12 0000007a205d99a0  x13 0000000000001110  x14 6e00000000000000  x15 0000000000000004
05-05 10:01:09.719  7663  7663 F DEBUG   :     x16 0000007a3e926858  x17 0000007c2c503bc0  x18 0000007ad99d0000  x19 0000007b7d7458f8
05-05 10:01:09.719  7663  7663 F DEBUG   :     x20 00000000dddddddd  x21 dddddddddddddddd  x22 0000007b7d74c000  x23 0000007b7d745900
05-05 10:01:09.719  7663  7663 F DEBUG   :     x24 0000007b7d745880  x25 0000007b7d74c000  x26 0000000000000004  x27 0000000000274400
05-05 10:01:09.719  7663  7663 F DEBUG   :     x28 000000008ac60075  x29 0000007b7d7458b0
05-05 10:01:09.719  7663  7663 F DEBUG   :     lr  0000007a3a3d02c4  sp  0000007b7d745880  pc  0000007a3a3d02c8  pst 00000000a0001000
05-05 10:01:09.719  7663  7663 F DEBUG   : 16 total frames
05-05 10:01:09.719  7663  7663 F DEBUG   : backtrace:
05-05 10:01:09.719  7663  7663 F DEBUG   :       #00 pc 00000000115bf2c8  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (TMulticastScriptDelegate<FNotThreadSafeDelegateMode>::TMulticastScriptDelegate(TMulticastScriptDelegate<FNotThreadSafeDelegateMode> const&)+124) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #01 pc 00000000115c6414  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #02 pc 0000000009811148  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (TGraphTask<FAsyncGraphTask>::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type, bool)+984) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #03 pc 0000000009803f64  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (FNamedTaskThread::ProcessTasksNamedThread(int, bool)+2092) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #04 pc 0000000009802408  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (FNamedTaskThread::ProcessTasksUntilQuit(int)+244) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #05 pc 000000000980133c  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete(TArray<TRefCountPtr<FGraphEvent>, TSizedInlineAllocator<4u, 32, TSizedDefaultAllocator<32> > > const&, ENamedThreads::Type)+1288) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #06 pc 00000000106a7174  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (FTickTaskSequencer::ReleaseTickGroup(ETickingGroup, bool)+2588) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #07 pc 00000000106a2138  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (FTickTaskManager::RunTickGroup(ETickingGroup, bool)+176) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #08 pc 000000000faa32b8  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (UWorld::Tick(ELevelTick, float)+9932) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.719  7663  7663 F DEBUG   :       #09 pc 000000000f7a7b1c  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (UGameEngine::Tick(float, bool)+4244) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.720  7663  7663 F DEBUG   :       #10 pc 0000000011133c84  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (FEngineLoop::Tick()+27712) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.720  7663  7663 F DEBUG   :       #11 pc 000000001112b57c  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (AndroidMain(android_app*)+4028) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.720  7663  7663 F DEBUG   :       #12 pc 000000001113ba5c  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (android_main+200) (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.720  7663  7663 F DEBUG   :       #13 pc 0000000011162bc4  /data/app/~~_KCG33vLj1fG6pXu7lAPkA==/com.a.ar-JGLEbkLMxfHoKv3GgB2L9w==/lib/arm64/libUnreal.so (BuildId: 27a7a96bded2d05c787c13119ec9ae6099f179ae)
05-05 10:01:09.720  7663  7663 F DEBUG   :       #14 pc 0000000000101d5c  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+204) (BuildId: 84a42637b3a421b801818f5793418fca)
05-05 10:01:09.720  7663  7663 F DEBUG   :       #15 pc 0000000000095bc0  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 84a42637b3a421b801818f5793418fca)

yups the symptom is a race condition. i’m trying to figure out why it triggers.
apparently that code can handle being called from other threads, but it’s failing a check for race conditions.

i think the problem is on whatever code is subscribed to your delegate.

because i don’t see an issue with the MoveTemp(TArary)
and being on the gamethread dispatching a delegate should be fine.
i’ve dispatched delegates on bg threads so that’s fine.

what confuses me is that being on the main thread you "shouldn’t":trade_mark: have issues like those.

try disconnecting everything from the delegate and see if that works. then try again.

my another guess is that “CallBackObj” is a custom object that somehow is getting auto-destroyed when the lambda finishes. and possibly from another thread.
but i would have expected a much longer stack trace if that were the case and a segfault not a race condition. but chances are that object could be doing something weird.

1 Like

yeah good point I will try this

That obj is static so it should be invisible to GC and persist throughout the game, but at the same time that might actually be the problem I might opt for subsystem instead of singleton class. the problem is that functions are all inside blueprint function library and that is preventing me from putting delegates inside it, delegates are inside another class (instance : CallbackObj)

that indeed was the case the problem was with the callbackobj, used weakptr in the end to check if the object is there before calling broadcast, thanks for the help

1 Like

great news! thanks for marking my post as solution.

static won’t make it invisible to the gc. if it’s a uobject or derived it WILL get GC’d (afaik).
and the usual problem is that people don’t use UPROPERTY tag, and the gc kills it really quick and they get a dangling pointer.
Using UPROPERTY will take care of the dangling pointer (one of the most powerful, and unknown feats of a UPROPERTY).
so if you make it static you might not have the uproperty.
Delegates are related to UObjects too. so if you don’t have a uproperty on the delegate it might cause issues as well. (i also recommend marking as transient, as serializing them can lead to unexpected results if you’re not super sure).

yeah i think the real issue is how you’ve designed the structure. it would help if you show it to me.

Definitely go with a subsystem. I don’t understand from the message why you have all inside a bpfl or if you’re using bps only. (subsystems can’t be created in bps afaik but don’t trust me, try it).
a static singleton somewhere will probably get gcd. which is probably what you’re experiencing.
i prefer subsystems above bpfl any day, much more powerful and future proof. except if you want to optimize to the last drop and are absolutely sure all your functions are static. (e.g. i’d use bpfl for a set of math functions, or text utils). that delegate does not belong to a bpfl.

if you are using bps, and you can’t make a subsystem. you can make a better singleton by defining a variable in one of the big objects and get it from there. E.g. GameMode or GameInstance.
Don’t make it weak or it will get gcd, just a regular TObjectPtr
On GameMode class MyGameMode


UPROPERTY(Transient)
TObjectPtr<MyClass> MySingleton = nullptr;

On GameMode::BeginPlay 
MySingleton = NewObject/SpawnActor<MyClass>(...);

When using:
Cast<MyGameMode>(UGameplayStatics::GetGameMode(this))->MySingleton->Whatever();
// (i would always check if it's valid like)
MyGameMode* const GM = Cast<MyGameMode>(UGameplayStatics::GetGameMode(this));
MyClass* const S = MyGameMode ? MyGameMode->MySingleton : nullptr;
if (UNLIKELY(!IsValid(S)) return;

Thanks for the help so far really appreciate it.
I looking for a way to create an android file system in order to do that I have used JNI (java native interface), inside java callback functions are used (native cpp functions that belong to a java class but are implemented inside cpp files one such call back is the one that the crash was happening on).
I haven’t used subsystems for only one reason I need a singleton class like the ones usually made un vanilla cpp, accessible from anywhere and everywhere, subsystems are not like this they need an unreal world context in order to access the game instance and subsequently subsystems which is only possible inside a class derived from UObject (this is all according to my knowledge I might be wrong) and obviously the java callbacks which belong to a java class don’t have access to.
As a result I used blueprint function library in order to do this and put all the delegates inside another class, made an instance of it and put it inside a static variable inside bpfl which was being GCd and led to crashes

WeakPtr was not the solution you were right the events inside bp all become Unbound after sometime

UCLASS()
class ANDROIDFILESYSTEM_API UAndroidFileSystemBlueprint : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	UAndroidFileSystemBlueprint (const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) {};

private:
    static UCallback* DelegateObj;
};

Theses are the java callback functions

#if PLATFORM_ANDROID
JNI_METHOD void Java_com_epicgames_unreal_GameActivity_OnFilePickerResult(JNIEnv* env, jclass clazz, jobjectArray result)
{
    TArray<FString> Result = JavaConvert::ConvertToStringArray(result);
	
    TArray<FString>* ResultPathPtr = new TArray<FString>(Result);
    
    AsyncTask(ENamedThreads::GameThread, [ResultPathPtr] () 
	{
		TWeakObjectPtr<UCallback> WeakCallback = DelegateObj;
		
		if (WeakCallback.IsValid())
		{
			UCallback* CallbackObj = WeakCallback.Get();

			if (IsValid(CallbackObj))
			{
				if (CallbackObj->GetFilePickerResultDelegate().IsBound())
				{
					CallbackObj->GetFilePickerResultDelegate().Broadcast(ResultPathPtr);
				}
			}
	}
		delete ResultPathPtr;
	});
}
#endif

This is the class that has all delegates

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOneParamDelegate, const TArray<FString>, Path);

UCLASS(BlueprintType)
class ANDROIDFILESYSTEM_API UCallback : public UObject
{
	GENERATED_BODY()

public:

	UFUNCTION() FORCEINLINE
	FOneParamDelegate& GetFilePickerResultDelegate() { return this->OnFilePickerResult; }

private:

    UPROPERTY(BlueprintAssignable)
	FOneParamDelegate OnFilePickerResult;

};