Stack overflow when calling UPrimitiveComponent::ComponentOverlapMulti from an FAsyncTask

Hi UE4 devs!

I am running in to an odd issue. I have an FAsyncTask that is created with an argument for a collision component. In the task’s DoWork call, ComponentOverlapMulti is called on that component. If I start the task with StartSynchronousTask() everything works as expected, but if I use StartBackgroundTask(), the call to ComponentOverlapMulti results in a stack overflow. Any idea what could cause this?

Call stack:

UE4Editor-Engine-Win64-Debug.dll!GeomOverlapMultiImp_PhysX<0>(const UWorld * World, const physx::PxGeometry & PGeom, const physx::PxTransform & PGeomPose, TArray & OutOverlaps, ECollisionChannel TraceChannel, const FCollisionQueryParams & Params, const FCollisionResponseParams & ResponseParams, const FCollisionObjectQueryParams & ObjectParams) Line 1571 C++

UE4Editor-Engine-Win64-Debug.dll!GeomOverlapMulti_PhysX(const UWorld * World, const physx::PxGeometry & PGeom, const physx::PxTransform & PGeomPose, TArray & OutOverlaps, ECollisionChannel TraceChannel, const FCollisionQueryParams & Params, const FCollisionResponseParams & ResponseParams, const FCollisionObjectQueryParams & ObjectParams) Line 1697 C++

UE4Editor-Engine-Win64-Debug.dll!FBodyInstance::OverlapMulti::__l66::() Line 4165 C++

UE4Editor-Engine-Win64-Debug.dll!UE4Function_Private::TFunctionRefCaller(void) const ,void __cdecl(void)>::Call(void * Obj) Line 193 C++

UE4Editor-Engine-Win64-Debug.dll!FBodyInstance::ExecuteOnPhysicsReadOnly(TFunctionRef Func) Line 2877 C++

UE4Editor-Engine-Win64-Debug.dll!FBodyInstance::OverlapMulti(TArray & InOutOverlaps, const UWorld * World, const FTransform * pWorldToComponent, const FVector & Pos, const FQuat & Quat, ECollisionChannel TestChannel, const FComponentQueryParams & Params, const FCollisionResponseParams & ResponseParams, const FCollisionObjectQueryParams & ObjectQueryParams) Line 4177 C++

UE4Editor-Engine-Win64-Debug.dll!UPrimitiveComponent::ComponentOverlapMultiImpl(TArray & OutOverlaps, const UWorld * World, const FVector & Pos, const FQuat & Quat, ECollisionChannel TestChannel, const FComponentQueryParams & Params, const FCollisionObjectQueryParams & ObjectQueryParams) Line 2273 C++

UE4Editor-Engine-Win64-Debug.dll!UPrimitiveComponent::ComponentOverlapMulti(TArray & OutOverlaps, const UWorld * World, const FVector & Pos, const FQuat & Rot, ECollisionChannel TestChannel, const FComponentQueryParams & Params, const FCollisionObjectQueryParams & ObjectQueryParams) Line 1761 C++

UE4Editor-VERAPlugin-Win64-Debug.dll!FVERAUpdate::DoWork() Line 55 C++

UE4Editor-VERAPlugin-Win64-Debug.dll!FAsyncTask::DoWork() Line 304 C++

UE4Editor-VERAPlugin-Win64-Debug.dll!FAsyncTask::DoThreadedWork() Line 326 C++

UE4Editor-Core-Win64-Debug.dll!FQueuedThread::Run() Line 336 C++

UE4Editor-Core-Win64-Debug.dll!FRunnableThreadWin::Run() Line 71 C++

UE4Editor-Core-Win64-Debug.dll!FRunnableThreadWin::GuardedRun() Line 48 C++

UE4Editor-Core-Win64-Debug.dll!FRunnableThreadWin::_ThreadProc(void * pThis) Line 67 C++

Answering my own question. The stack size in the global thread pool was not large enough. By creating a new thread pool with a stack size of 128kb I was able to get this running.

I’ve also just hit this issue. The default stack size of 32KB for the pool threads seems rather small and likely to cause issues like this, would be nice to see that increased in a future UE4 version.

@lifespan could you expand on exactly what you did. I’m having this same issue, and sadly your description of what you did hasn’t given me much joy on replicating what you did. Where exactly is the global thread pool and how did you change the size/create a new one?

You just need to set a larger stack size when creating the thread pool:

FQueuedThreadPool* ThreadPool = GThreadPool;
ThreadPool = FQueuedThreadPool::Allocate();
ThreadPool->Create(1,stack size here, TPri_BelowNormal);