Author Topic: UISK: Error with Latest TNet  (Read 5877 times)

broknecho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
UISK: Error with Latest TNet
« on: July 19, 2013, 01:44:20 AM »
Hey!

I tried starting a brand new project tonight and I'm getting a weird error after importing the TNet Integration part of the UISK setup document.  The packages I have imported (and in this order):

1- Import UISK 1.0.0.0 from the asset store
2- Import NGUI from download link v.2.6.3
3- Import TNet from download link v1.7.2c

Following the UISK setup document, when I get to the step right after you import the TNet Integration package where you are to go to the Direct Connect to test this step, there is an error:

CompareBaseObjectsInternal  can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.

This happens right after click the "Direct" button and when it's loading the internal/external address.  The internal Address is updated but it's erroring around where it's updating the UILabel for the external address.

The call stack shows the exception in the UIDirectConnect.cs script.

Also I'm using Unity Free v4.1.3f3.

Please let me know if you need any other information from my setup.

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISK: Error with Latest TNet
« Reply #1 on: July 19, 2013, 02:01:58 AM »
The kit was created with those same exact versions -- 2.6.3 and 1.7.2c. Can you provide more information like a full stack trace?

broknecho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: UISK: Error with Latest TNet
« Reply #2 on: July 19, 2013, 09:53:21 AM »
Stack:
  • UnityEngine.Object.CompareBaseObjects (lhs=System.ArgumentException: ToString  can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function., rhs=(null)) in C:\BuildAgent\work\7535de4ca26c26ac\Runtime\ExportGenerated\Editor\UnityEngineObject.cs:47
  • UnityEngine.Object.op_Inequality (x=System.ArgumentException: ToString  can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function., y=(null)) in C:\BuildAgent\work\7535de4ca26c26ac\Runtime\ExportGenerated\Editor\UnityEngineObject.cs:144
  • UILabel.MakePixelPerfect () in D:\Projects\Unity\NetAttack\Assets\NGUI\Scripts\UI\UILabel.cs:568
  • UILabel.set_text (value="192.168.x.xxx") in D:\Projects\Unity\NetAttack\Assets\NGUI\Scripts\UI\UILabel.cs:143
  • UIDirectConnect.OnResolvedIPs (local={192.168.x.xxx}, ext={96.51.xx.xxx}) in D:\Projects\Unity\NetAttack\Assets\StarlinkUI\Scripts\Custom\UI\UIDirectConnect.cs:49
  • TNet.Tools.ResolveThread (obj={TNet.Tools.OnResolvedIPs}) in D:\Projects\Unity\NetAttack\Assets\TNet\Common\TNTools.cs:148

I just manually removed a few digits from the IPs above.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISK: Error with Latest TNet
« Reply #3 on: July 19, 2013, 10:29:20 AM »
Curious. I was able to reproduce it on an Android platform. Here is a fix:
  1. using UnityEngine;
  2. using System.Net;
  3. using TNet;
  4.  
  5. public class UIDirectConnect : MonoBehaviour
  6. {
  7.         public UIButton button;
  8.         public UILabel buttonText;
  9.         public UILabel infoLabel;
  10.         public UIInput serverAddress;
  11.         public UILabel internalIP;
  12.         public UILabel externalIP;
  13.         public UIPanel channelListWindow;
  14.         public GameObject clearButton;
  15.  
  16.         bool mConnecting = false;
  17.         bool mIpResolved = false;
  18.         IPAddress mLocal;
  19.         IPAddress mExternal;
  20.  
  21.         void Start ()
  22.         {
  23. #if UNITY_WEBPLAYER
  24.                 Tools.ipCheckerUrl = "http://starlink.tasharen.com/ip.php";
  25.                 infoLabel.text = Localization.Localize("Direct Note 3");
  26. #else
  27.                 infoLabel.text = Localization.Localize("Direct Note 2");
  28. #endif
  29.                 internalIP.text = Localization.Localize("Searching");
  30.                 externalIP.text = Localization.Localize("Searching");
  31.                 UIEventListener.Get(button.gameObject).onClick = OnButtonClick;
  32.                 UIEventListener.Get(serverAddress.gameObject).onSelect = OnSelectInput;
  33.                 UIEventListener.Get(clearButton).onClick = OnClear;
  34.                 serverAddress.onSubmit = Connect;
  35.                 Tools.ResolveIPs(OnResolvedIPs);
  36.                 UpdateButtonText();
  37.         }
  38.  
  39.         void OnClear (GameObject go)
  40.         {
  41.                 serverAddress.text = "";
  42.                 UpdateButtonText();
  43.         }
  44.  
  45.         void OnSelectInput (GameObject go, bool selected)
  46.         {
  47.                 UpdateButtonText();
  48.         }
  49.  
  50.         void OnResolvedIPs (IPAddress local, IPAddress ext)
  51.         {
  52.                 mLocal = local;
  53.                 mExternal = ext;
  54.                 mIpResolved = true;
  55.         }
  56.  
  57.         void Update ()
  58.         {
  59.                 if (mIpResolved)
  60.                 {
  61.                         internalIP.text = mLocal.ToString();
  62.                         externalIP.text = mExternal.ToString();
  63.                         mIpResolved = false;
  64.                 }
  65.         }
  66.  
  67.         void OnEnable ()
  68.         {
  69.                 TNManager.Disconnect();
  70.                 UpdateButtonText();
  71.         }
  72.  
  73.         void OnButtonClick (GameObject go)
  74.         {
  75.                 if (TNServerInstance.isActive)
  76.                 {
  77.                         TNServerInstance.Stop();
  78.                         UpdateButtonText();
  79.                 }
  80.                 else if (!string.IsNullOrEmpty(serverAddress.text))
  81.                 {
  82.                         Connect(serverAddress.text);
  83.                 }
  84. #if !UNITY_WEBPLAYER
  85.                 else
  86.                 {
  87.                         TNServerInstance.serverName = "Direct Server";
  88.  
  89.                         if (TNServerInstance.Start(5127))
  90.                         {
  91.                                 TNManager.Connect("127.0.0.1", 5127);
  92.                         }
  93.                         else
  94.                         {
  95.                                 UIMessageBox.Show(Localization.Localize("Unable to Start"), Localization.Localize("Unable to Start Info"));
  96.                         }
  97.                         Connect(serverAddress.text);
  98.                         UpdateButtonText();
  99.                 }
  100. #endif
  101.         }
  102.  
  103.         void Connect (string val)
  104.         {
  105.                 if (!string.IsNullOrEmpty(val))
  106.                 {
  107.                         mConnecting = true;
  108.                         TNManager.Connect(val, 5127);
  109.                         UpdateButtonText();
  110.                 }
  111.         }
  112.  
  113.         void OnNetworkConnect (bool success, string errmsg)
  114.         {
  115.                 if (!success)
  116.                 {
  117.                         UIMessageBox.Show(Localization.Localize("Unable to Connect"), errmsg);
  118.                 }
  119.  
  120.                 mConnecting = false;
  121.                 UpdateButtonText();
  122.  
  123.                 if (success)
  124.                 {
  125.                         UIWindow.Show(channelListWindow);
  126.                 }
  127.         }
  128.  
  129.         void UpdateButtonText ()
  130.         {
  131.                 if (mConnecting)
  132.                 {
  133.                         button.isEnabled = false;
  134.                         buttonText.text = Localization.Localize("Connecting");
  135.                 }
  136.                 else if (TNServerInstance.isActive)
  137.                 {
  138.                         button.isEnabled = true;
  139.                         buttonText.text = Localization.Localize("Stop");
  140.                 }
  141. #if UNITY_WEBPLAYER
  142.                 else if (string.IsNullOrEmpty(serverAddress.text))
  143.                 {
  144.                         buttonText.text = Localization.Localize("Connect");
  145.                         button.isEnabled = false;
  146.                 }
  147. #else
  148.                 else if (string.IsNullOrEmpty(serverAddress.text))
  149.                 {
  150.                         button.isEnabled = true;
  151.                         buttonText.text = Localization.Localize("Start");
  152.                 }
  153. #endif
  154.                 else
  155.                 {
  156.                         button.isEnabled = true;
  157.                         buttonText.text = Localization.Localize("Connect");
  158.                 }
  159.         }
  160. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISK: Error with Latest TNet
« Reply #4 on: July 19, 2013, 10:54:18 AM »
I've also submitted a fix to the package itself (1.0.1).

broknecho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: UISK: Error with Latest TNet
« Reply #5 on: July 19, 2013, 11:07:55 AM »
Works Great!   Thanks!  Your support speed is unmatched  :D

Also just to add, I was in the editor with a brand new empty project.  Windows version of Unity.