endel / NativeWebSocket

🔌 WebSocket client for Unity - with no external dependencies (WebGL, Native, Android, iOS, UWP)
Other
1.2k stars 158 forks source link

Unity app Crashing when reopening from Background after idling for ~10+ minutes #49

Open JimmyDelaney opened 3 years ago

JimmyDelaney commented 3 years ago

This crash seems like it only occurs in iOS 13+ and is intermittent. I get it occur about 20% of the time. The error in xCode reads something like IL2CPP Threadpool worker (44): EXC_BAD_ACCESS (code=1, address=0x18). The address part slightly changes sometimes, but the rest is the same.

I created an empty project where I just connect to our server and then minimize the app by tapping the power button on the iPad. After waiting ~10 minutes or so reopen the app. About 20% of the time, the app will crash. Xcode doesn't seem to be logging anything from Unity. I just get the error After applicationwillenterforeground and before applicationdidbecomeactive. I've tried debugging this for a while now, with little luck because of the lack of logging. I did notice during debugging when I commented out the await Receive() call in Websocket.cs Connect() it stopped crashing, but of course I can't receive messages at that point.

Has anyone else had a similar issue? Anyone have any ideas?

divillysausages commented 3 years ago

If commenting the Receive() call from Connect() stops it crashing, you can split it out to a separate function - with the added benefit that Connect() now returns after the connection is successful and not when the connection is finished.

See https://github.com/endel/NativeWebSocket/issues/45#issuecomment-882635332 for an example of how I do it