Open VitorOI opened 5 months ago
The downstream callbacks are cleared here: https://github.com/getnamo/UDP-Unreal/blob/5d49e2e3361480a6776625d6c23a6ff0578082b9/Source/UDPWrapper/Private/UDPComponent.cpp#L346
You can likely unbind the OnDataReceived somewhere here: https://github.com/getnamo/UDP-Unreal/blob/5d49e2e3361480a6776625d6c23a6ff0578082b9/Source/UDPWrapper/Private/UDPComponent.cpp#L321 although it does get called with stop and deleted on Close so I don't quite see how it's being called after it's been cleared? Maybe a wait for a clean close might be needed?
My recommendation would be to close the connection before endplay, that should work as intended even if more data arrives.
We concluded it is the AsyncTask that somehow still runs when changing level. By setting Settings.bReceiveDataOnGameThread to false on the Actor that handles the UDP Component (this on BeginPlay), we are able to avoid the crash.
Still needs more testing but seems to be a working solution for now
We have a setup where we're constantly sending data at a 40ms rate, but the application occasionally crashes when we leave the level to our Main Menu level.
We found the culprit to be the lambda function bound to "OnDataReceived" in UDPComponent, line 270. Since this bind is not cleared on EndPlay, the lambda persists and is called constantly even while being destroyed, which causes the crash.