Hey everyone,
I have an issue with some inconsistent crashing. The crash occurs in a function that is called on a UObject* on the game thread from another thread via FNonAbandonableTask. The crash occurs when the function tries to use the object itself (this). The crash is inconsistent, and, the weird part is, the object isn’t a nullptr when the crash occurs. Rather, it seems corrupted or… something.

Here is the full code:
class AsyncTracer : public FNonAbandonableTask
{
public:
UAxisSearcher* SearcherCaller;public:
AsyncTracer(UAxisSearcher* InSearcher);
~AsyncTracer();FORCEINLINE TStatId GetStatId() const { RETURN_QUICK_DECLARE_CYCLE_STAT(AsyncTracer, STATGROUP_ThreadPoolAsyncTasks); }
void DoWork();
};
AsyncTracer::AsyncTracer(UAxisSearcher* InSearcher)
:SearcherCaller(InSearcher)
{
}
AsyncTracer::~AsyncTracer()
{
}
void AsyncTracer::DoWork()
{
...
if (IsValid(SearcherCaller)) /*<- This validity check does not prevent the crash!*/
{
UE_LOG(LogTemp, Log, TEXT("About to call begin path finds on: %s"), *SearcherCaller->GetName()); /*<-This log is NEVER printed when the crash occurs!*/
AsyncTask(ENamedThreads::GameThread, [=]() { SearcherCaller->BeginPathFinds(bAnyPointValid); } );
}
}
Async task is created on the game thread.
void UAxisSearcher::BeginTraces()
{
(new FAutoDeleteAsyncTask(this))->StartBackgroundTask();
}
Crash occurs in this function:
void UAxisSearcher::BeginPathFinds(bool bValidPointsAvailable)
{
if (!bValidPointsAvailable)
{
/Maybe change axis?/
return;
}
UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetCurrent(this); /<— Crash occurs in this line!/
if (!NavSystem) { return; }
…
}
Additional details:
The used UAxisSearcher* is part of a struct and is marked with UPROPERTY(). The struct is used in a TMap on an actor, and is marked with UPROPERTY(Transient).
Any help would be greatly appreciated. Thanks.