There’s no compile error. But the thread’s Run() function is not executed when I run the game, I don’t know why.
Can you help me ?
GameMode.cpp:
ARoboRev_WinGameMode::ARoboRev_WinGameMode(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
int i = 0;
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "Before Thread!");
ThreadX* t = ThreadX::JoyInit(&i);
while (i == 0)
{
int x = 0;
}
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "After Thread!");
}
I got the thread working. But When I run from visual studio, and hit play in Unreal Editor, the thread executes once.
Next time, if I hit Stop and hit Play again, it doesn’t work…
Not sure why.
This is because the Constructor in Unreal is only called if you Start the editor. If you run it standalone it will always run as expected. Its just the Editor which makes trouble here. Same with static vars. They keep theyr state betwean multiple “Play” runs. The best way (If you have a ssd) is to start Visual Studio and then debug the Game (F5). With this way you also see exactly where NullPtr exceptions happening and you will allways get a fresh Stack of static vars and Constructors. But also dont spawn Threads in the Constructor. Use a initialization funktion (call her initThread or something) which you can call with a beginPlay event.