Hello,
I have an AsyncTask that sets up connection to database so that there is no delay in the main game thread.
Problem is if lets say it downloads an image and before it has completed I press escape and exit out of play mode the engine crashes.
here is my code:
class MultithreadedTask : public FNonAbandonableTask {public:UObject* object;
// ConstructorMultithreadedTask(UObject* object) { this->object = object; }
FORCEINLINE TStatId GetStatId() const {RETURN_QUICK_DECLARE_CYCLE_STAT(MultithreadedTask, STATGROUP_ThreadPoolAsyncTasks);}
void DoWork(){IIMultithreading::Execute_MultithreadedFunction(object);}};
The Task class is just calling the Execute Interface method with UObject passed as a reference.
and below is the implementation of a blueprint callable function that takes in a UObject and creates and starts a new background task.
void UMultithreadedFunctionLibrary::CallMultithreadedFunction(UObject* Object){(new FAutoDeleteAsyncTask<MultithreadedTask>(Object))->StartBackgroundTask();}
Now, If the task is finished and i exit or change level everything works fine the engine does not crash. but if I change the level or jump out of playmode before the task has finished the engine crashes with Access Violation error messages.
I have tried to use ASyncTasks and manually Cancel and abandon it on BeginDestroy() but it turned out to be even worse than this.
I just don’t want my engine to crash if i switch level or exit play mode