I have a c++ class which includes a pthread (pthread_create). This thread will execute the callback format :
void (*)(int iSize, int iCode);
At the moment, In a class :
UCLASS() class APPREALKITTEST_API AAppRealKitTestGameMode
I have a public method :
void AAppRealKitTestGameMode::receiveMessageCallback(int iSize, int iCode) {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString("INFO: %d", iSize));
*//It is always the crash at this line*
}
How can I update the message from pthread to into UI?
Notes : my library is always OK in XCode and android NDK.
I’m not sure, but is GEngine and the AddOnScreenDebugMessage method thread-safe? If I understand correctly, it sounds like you’re calling this from the callback directly invoked by the pthread.
I would cache the results in some sort of thread-safe container and then access them from the main thread. That’s without knowing what you’re really trying to do, however, so take this with a grain of salt
Hi @ ,
I tried to execute the callback function from a thread (not main thread).
Have any way to execute the method in a child thread such as : “runOnUiThread” in Android ?
Thanks !!
Can someone please test if you can actually use GEngine->AddOnScreenDebugMessage from a non-main thread? I’ve had this issue with other UE4 code that asserts or collides/races if you’re not on the main thread. I’m leaving work so I don’t have time
Hi @ ,
Unreal Editor maybe not allow to execute “GEngine->AddOnScreenDebugMessage” from child thread.
So, i only set the value for the variable which defined from main thread.
After that, i can show this value in UI thread.
Thank so much !!!