Author Topic: (1.9.6b) iOS Freeze/Crash on Sleep  (Read 3312 times)

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
(1.9.6b) iOS Freeze/Crash on Sleep
« on: August 05, 2014, 06:52:33 PM »
We're running into a problem when we put our devices to sleep the device will be unresponsive when we awake. We did a test on the examples and it is happening there as well. We're only targeting iOS and Editor right now in a LAN-only connection environment.

We deploy the example on an iOS device, and we connect to a server fine. However, as soon as the app is put to sleep the app becomes unresponsive. We haven't spent a lot of time digging into the problem but it seems to affect all of our iOS devices (various iPads and iPhones) so I figure you'd be able to replicate the problem fairly easily.

Connect to a server, launch and example, do some network sends, put the device to sleep (tapping the wake/sleep button), give it 5 seconds, and then rewake the device by tapping the wake/sleep again. The Connect dialog will appear, but the app will not pull up the server list nor is the other UI is not responsible. We've tried it on our project (which uses NGUI) and the same problem happens there in our lobby browser.

We'll continue to do more digging and update this topic with more information when we can get it to you. In the meantime, could you try to look into this problem and see if it is happening on your hardware? I looked through the docs, but I didn't see a best practice in regards to how we need to close sockets or handle the sleep functionality so that the app doesn't freeze.

We've tried with multicasting on and off, and it doesn't seem to affect the problem.

Thanks!

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
Re: (1.9.6b) iOS Freeze/Crash on Sleep
« Reply #1 on: August 06, 2014, 12:48:33 PM »
So we did some digging into this problem, and I'd like to see a future version of TNET potentially resolve these problems internally.

One problem was that the TNUDPLobbyClient was crashing during its update when we would pause/resume. So basically we need to be able to turn it off (enabled = false) when the application goes to sleep. I think this might be considering doing automatically. Just be aware that the system should keep a remembered value for its enabled state so that it doesn't turn on if it was previously turned off.

The second problem was a little less clear cut. The problem has to do with what is the correct process to shutdown the server when we go to pause. The best solution I came up with is waiting until we resume the application before disconnecting and stopping the server. I assume it has something to do with the timing async nature of networking that the server needs more time to shutdown than Application pause gives it.

Another thing is that debugging the app through XCode produces a lot of errors and exceptions that doesn't seem to stop the app if XCode is disconnected.

However, I'd be curious to hear any other solutions that may be better from your perspective?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: (1.9.6b) iOS Freeze/Crash on Sleep
« Reply #2 on: August 06, 2014, 08:25:56 PM »
TNUdpLobbyClient crashing during its update? Where, exactly? Also, UDP lobby client can be turned on and off freely. I do that in Starlink actually -- I have both UDP and TCP lobby clients, and I turn on one and turn off the other when I switch from online to LAN gameplay and vice versa. Do you not receive OnDisable when the app goes to sleep? Perhaps we should add:
  1. void OnApplicationPause (bool paused) { if (paused) OnDisable(); else OnEnable(); }
to it? Can you give that a try? I would also suggest stopping the server in OnApplicationPause as well.

P.S. I'd probably only re-enable it if it was actually enabled though:
  1.     bool mReEnable = false;
  2.  
  3.         void OnApplicationPause (bool paused)
  4.         {
  5.                 if (paused)
  6.                 {
  7.                         if (isActive)
  8.                         {
  9.                                 mReEnable = true;
  10.                                 OnDisable();
  11.                         }
  12.                 }
  13.                 else if (mReEnable)
  14.                 {
  15.                         mReEnable = false;
  16.                         OnEnable();
  17.                 }
  18.         }

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
Re: (1.9.6b) iOS Freeze/Crash on Sleep
« Reply #3 on: August 07, 2014, 12:59:02 PM »
TNUdpLobbyClient will crash during its Update() when it is trying to send on a socket that is probably already closed (line 126).

We ended up doing something very similar to what you had documented, but instead of directly calling OnEnable/Disable we set the script enabled or disabled directly by using .enabled.

Are there any recommendations on how best we can terminate the server during the pause. Do you see any problems with killed the server once the app is resumed?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: (1.9.6b) iOS Freeze/Crash on Sleep
« Reply #4 on: August 08, 2014, 06:55:08 AM »
Shutting down the server when the app gets paused seems like a sensible idea even the issue aside. I added that last code block into TNet, and it stops the server then re-enables it when the app resumes.