Author Topic: TNServerInstance.Stop() crash on iOS  (Read 3533 times)

IZLogic

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
    • IZLogic!
TNServerInstance.Stop() crash on iOS
« on: July 08, 2014, 09:18:35 AM »
I'm facing this issue on my game, but I can reproduce it also on your menu sample (TNet 1.9.5c) in a clean project.
I cannot stop the server created on the device (iPhone4/iPad2 with iOS7).
XCode throws the following error about "server.dat" without stopping the server:
  1. UnauthorizedAccessException: Access to the path "/server.dat" is denied.
  2.   at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 bla bla bla...


Changing the instantiation of the server to TNServerInstance.Start(serverTcpPort, udpPort, lobby.remotePort, null, type) and the stop with TNServerInstance.Stop(), result in a SIGUSR1 crash.

No problem in editor, just on devices.

I'm stuck, any suggestion?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNServerInstance.Stop() crash on iOS
« Reply #1 on: July 08, 2014, 04:35:24 PM »
Yup, known issue, thanks. I resolved it earlier by putting the file read/writes into try/catch blocks. The fix will be available in the next update (this week), but I suggest you put the file read/writes into try/catch blocks yourself in the meantime.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNServerInstance.Stop() crash on iOS
« Reply #2 on: July 08, 2014, 04:39:44 PM »
You can find them at the bottom of TNTools.cs btw:
  1.         /// <summary>
  2.         /// Write the specified file, creating all the subdirectories in the process.
  3.         /// </summary>
  4.  
  5.         static public bool WriteFile (string fileName, byte[] data)
  6.         {
  7. #if !UNITY_WEBPLAYER && !UNITY_FLASH && !UNITY_METRO && !UNITY_WP8
  8.                 if (data == null || data.Length == 0)
  9.                 {
  10.                         return DeleteFile(fileName);
  11.                 }
  12.                 else
  13.                 {
  14.                         try
  15.                         {
  16.                                 string dir = Path.GetDirectoryName(fileName);
  17.                                 if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir)) Directory.CreateDirectory(dir);
  18.                                 File.WriteAllBytes(fileName, data);
  19.                                 return true;
  20.                         }
  21.                         catch (System.Exception) { }
  22.                 }
  23.                 return false;
  24. #endif
  25.         }
  26.  
  27.         /// <summary>
  28.         /// Read the specified file, returning all bytes read.
  29.         /// </summary>
  30.  
  31.         static public byte[] ReadFile (string fileName)
  32.         {
  33. #if !UNITY_WEBPLAYER && !UNITY_FLASH && !UNITY_METRO && !UNITY_WP8
  34.                 try
  35.                 {
  36.                         if (File.Exists(fileName))
  37.                                 return File.ReadAllBytes(fileName);
  38.                 }
  39.                 catch (System.Exception) { }
  40. #endif
  41.                 return null;
  42.         }
  43.  
  44.         /// <summary>
  45.         /// Delete the specified file, if it exists.
  46.         /// </summary>
  47.  
  48.         static public bool DeleteFile (string fileName)
  49.         {
  50. #if !UNITY_WEBPLAYER && !UNITY_FLASH && !UNITY_METRO && !UNITY_WP8
  51.                 try
  52.                 {
  53.                         if (File.Exists(fileName))
  54.                                 File.Delete(fileName);
  55.                         return true;
  56.                 }
  57.                 catch (System.Exception) { }
  58.                 return false;
  59. #endif
  60.         }

IZLogic

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
    • IZLogic!
Re: TNServerInstance.Stop() crash on iOS
« Reply #3 on: July 09, 2014, 03:19:58 AM »
Thanks.
Now it passes the server.dat writing correctly, but the device is still crashing (SIGUSR1) when plugged in to Xcode.
Seems that Xcode has some problem with the TN_UDPLobbyServer thread during the stop.
If I unplug the device no crash and the server stops correctly.
I have Xcode 5.1.1 and Unity 4.5.1.

Any suggestion?
« Last Edit: July 09, 2014, 03:25:12 AM by IZLogic »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNServerInstance.Stop() crash on iOS
« Reply #4 on: July 09, 2014, 02:27:26 PM »
Off the top of my head -- nope. I don't see anything else there. You can try commenting things out to see what actually causes it... might help.

dereklam0528

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: TNServerInstance.Stop() crash on iOS
« Reply #5 on: August 06, 2014, 08:16:38 PM »
Hi,

Does it happen in current version, 1.9.6b? When is this going to get updated?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNServerInstance.Stop() crash on iOS
« Reply #6 on: August 06, 2014, 08:34:52 PM »
I'd need more info on it in order to fix it. As I understand it it's a debugging-only issue, only happens when testing while the device is connected to XCode. It doesn't occur at any other time, so none of the players will ever run into this. Without more info to go by, all I can suggest is adding a try/catch block to TNUdpLobbyClient.OnDisable to see if that will help.
  1.         protected override void OnDisable ()
  2.         {
  3.                 isActive = false;
  4.                 base.OnDisable();
  5.  
  6.                 try
  7.                 {
  8.                         mUdp.Stop();
  9.  
  10.                         if (mRequest != null)
  11.                         {
  12.                                 mRequest.Recycle();
  13.                                 mRequest = null;
  14.                         }
  15.                         if (onChange != null) onChange();
  16.                 }
  17.                 catch (System.Exception) { }
  18.         }