I am using a WebSocket and applying a Lambda to the OnMessage callback.
Socket->OnMessage().AddLambda([&](const FString& Message)
{
if (IsValid(this))
{
this->StartHeartbeat();
}
});
And in StartHeartbeat function I create a timer like this:
void UStartGateway::StartHeartbeat()
{
HeartbeatCallback.BindWeakLambda(this, [this]
{
Heartbeat();
});
GetWorld()->GetTimerManager().SetTimer(HeartbeatHandle, HeartbeatCallback, HeartbeatInterval / 1000, true);
}
And when I receive a message on the websocket I get an access violation error and the editor crashes. The error specifically points to the timer setting line. Any help is greatly appreciated. I really don’t understand the issue, since ‘this’ is being captured in both lambdas and I’m pretty sure that the object isn’t being destroyed somehow, but I have IsValid(this) protecting the StartHeartbeat from running anyway.