Crash when get data from from pthread

Hi admin,

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.

Thanks !!!

Hi everybody,
Please help me !!!
Thanks!!!

It’s crashing on the GEngine->AddOnScreenDebugMessage line? What happens if you comment that line out?

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 :slight_smile:

Hi ,
If I comment that line, It is OK.
Maybe it only crash when I try to send the message to UI (view UI).
Thanks!!!

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 !!

Are you checking to see if GEngine!= NULL ? It might be that it is undefined in whatever context you are using it?

Are you checking to see if GEngine!= NULL ? It might be that it is undefined in whatever context you are using it?
[/QUOTE]

Hi ,
I had tried this way but it still crash.
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 :frowning:

Thanks for supporting.
Thank so much. Have a nice day !!!

Hi all,
We had just found a way to fix this issue.
Thanks for supporting.
Nice a day !!! :slight_smile:

The usual etiquette in this situation is to share the fix - it enables people that find this thread in the future to know how you fixed it :slight_smile:

So… how did you solve it? What was the issue?

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 !!!