Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: IZLogic on July 08, 2014, 09:18:35 AM

Title: TNServerInstance.Stop() crash on iOS
Post by: IZLogic 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?
Title: Re: TNServerInstance.Stop() crash on iOS
Post by: ArenMook 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.
Title: Re: TNServerInstance.Stop() crash on iOS
Post by: ArenMook 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.         }
Title: Re: TNServerInstance.Stop() crash on iOS
Post by: IZLogic 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?
Title: Re: TNServerInstance.Stop() crash on iOS
Post by: ArenMook 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.
Title: Re: TNServerInstance.Stop() crash on iOS
Post by: dereklam0528 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?
Title: Re: TNServerInstance.Stop() crash on iOS
Post by: ArenMook 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.         }