Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why UE4 becomes stuttered after play if the rosbridge_server in another machine doesn't open? #175

Open
webercheng opened this issue Jul 15, 2022 · 2 comments

Comments

@webercheng
Copy link

In my case, I run UE4(with ROSIntegration) in win10 but I didn't start the rosbridge_server(rosbridge_tcp) in another pc. However. After I clicked the "Play" button, the UE4 world became stuttered. This will also happen if I terminate the rosbridge_server on purpose.

@webercheng
Copy link
Author

I found this caused by "if (!_sock->Connect(*addr))" in "bool TCPConnection::Init(std::string ip_addr, int port)" which consumes at least 2 seconds in my system。"void UROSIntegrationGameInstance::Init()" will be called in "UROSIntegrationGameInstance::CheckROSBridgeHealth" periodically while rosbridge_server not started.
I tried to fix this but still encountered some problems.

@webercheng
Copy link
Author

Problem solved! The root cause is ”_sock->Connect(*addr)“ works in blocking mode, blocking time will be affected by system implementation which is unpredictable. So it's necessary to set non-block mode first.

I tried to fix like this:

  1. TCPConnection.cpp
    bool TCPConnection::Init(std::string ip_addr, int port)
    {
    ...
    #if 0
    if (!_sock->Connect(*addr))
    #else

    bool bConnected = false;
    _sock->SetNonBlocking(true);
    bConnected = _sock->Connect(*addr);
    _sock->SetNonBlocking(false);
    // If using _sock->Wait also blocks
    if (bConnected ) //&& _sock->Wait(ESocketWaitConditions::WaitForWrite, FTimespan::FromSeconds(2)))
    {
    // do nothing
    }
    else
    #endif
    {
    return false;
    }
    ...
    }

  2. In ROSIntegrationGameInstance.cpp

void UROSIntegrationGameInstance::Init()
{
#if 0
if (!bTimerSet)
{
bTimerSet = true;
GetTimerManager().SetTimer(TimerHandle_CheckHealth, this, &UROSIntegrationGameInstance::CheckROSBridgeHealth, 1.0f, true, 5.0f);
}
#else
if (!bTimerSet)
{
bTimerSet = true;
GetTimerManager().SetTimer(TimerHandle_CheckHealth, this, &UROSIntegrationGameInstance::CheckROSBridgeHealth, 5.0f, true, 5.0f);
}
#endif
}

This is not the optimal solution but combined these two changes does help to my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant