Dear community, I have a strange problem with interfaces.
My async task does some interface calls in loop via Execute_… method. And at that moment when GC starts, next call throws assertion !IsUnreachable() on calling object, leading to engine crash. But this is only the case, i.e. if i do these calls in game thread or do async call the normal method of the same object in same conditions, everything happens ok. Experiments around this showed, that when I pause my custom thread to allow GC accomplish its work and then run it again, everything happens ok and no objects are destructed. In what may be the reason for this? The only idea i have for now is some problems with thread safety of interface calls.
Are you able to hold a strong reference to the object in question and wrap any code that uses it in IsPendingKill (IsKillPending?)
Thank you, BrUnO. I’ll try this as soon as possible.
No, it isn’t safe in large majority of cases.
What you can do from your Execute() is invoke a static function within GameThread from your AsyncTask which then executes UInterface calls for you, something like this:
DECLARE_CYCLE_STAT(TEXT("FSimpleDelegateGraphTask.MyTask"),STAT_FSimpleDelegateGraphTask_MyTask,STATGROUP_TaskGraphTasks);
if (IsInGameThread()) {
MyStaticFunc(SomeParam);
} else {
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
FSimpleDelegateGraphTask::FDelegate::CreateStatic(&MyStaticFunc,SomeParam),
GET_STATID(STAT_FSimpleDelegateGraphTask_MyTask),
nullptr,
ENamedThreads::GameThread
);
}
static void MyStaticFunc(USomeType* SomeInputParam) {
// call interface functions here...
}
I would like to raise this issue,
sometimes when calling the interface, the object does not pass the “! IsUnreachable ()” check.
Is there a safe way to call an interface ???
the function is a constant getter.
my architecture does not allow me to wait until a delegate is called in the main thread and sends data back.
UE_4.20\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp