Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Katalyst on January 29, 2014, 09:37:00 PM

Title: Strange Build Behavior
Post by: Katalyst on January 29, 2014, 09:37:00 PM
Not sure if this error is somehow TNet related as TNet does pop up in the error log. I apologize if it isn't and posting here.

I finally have my lobby working flawlessly... in the editor. Whether hosting or connecting to a built client, the editor always works perfectly without errors.  When I build out a client, it never matches what running in the editor sees, whether hosting or connecting. The host for example, always show up in slot two instead of slot one like its supposed to. When switching teams from that slot, they go to slot 9, instead of the first open slot on the other team, slot 5. But all of this works and is shown correctly in the editor.

At first I thought maybe it was a network sync problem but when I put in a bunch of debugging things, everything was checking out. The arrays were in the correct order and length, ID's were where they should be. Nothing seemed wrong.

Well today, I finally ticked the script debugging box on building out my clients to test with. Sure enough, errors pop up that do not happen within the editor. Namely the one in the image. This error pops up as soon as you host a game when on a built client but not when running it in the editor.

Line 25 that is listed in the code is part of this code:
  1. void OnNetworkJoinChannel (bool result, string message) {
  2.                 if(result) {
  3.                         if(TNManager.isHosting) {
  4.                                 playersID = new int[maxPlayersSize];
  5.                                 playersTeam = new int[maxPlayersSize];
  6.                                 playersReady = new bool[maxPlayersSize];
  7.                                 playersID[0] = TNManager.hostID; //This is line 25.
  8.                                 halfSize = maxPlayersSize/2;
  9.                                 InitializePlayerNameList();
  10.                                 //PrintPlayerIDList();
  11.                         }
  12.                         else
  13.                                 tno.Send("RequestUpdate", Target.Host, TNManager.playerID);
  14.  
  15.                         mRebuild = true;
  16.                 }
  17.         }
maxPlayersSize is fed to this script before the arrays are initialized to make sure their size is correct. Even if I predefine the list to be 10 in size within the editor, I still get an array index error.
Title: Re: Strange Build Behavior
Post by: ArenMook on January 29, 2014, 11:17:56 PM
It tells you that the problem is here:
  1. playersID[0]
which implies that maxPlayersSize is likely zero.
Title: Re: Strange Build Behavior
Post by: Katalyst on January 30, 2014, 02:23:57 AM
  1. void OnNetworkJoinChannel (bool result, string message) {
  2.                 if(result) {
  3.                         if(TNManager.isHosting) {
  4.                                 playersID = new int[maxPlayersSize];
  5.                                 playersTeam = new int[maxPlayersSize];
  6.                                 playersReady = new bool[maxPlayersSize];
  7.                                 PrintPlayerIDList();//<-- Added code.
  8.                                 playersID[0] = TNManager.hostID;
  9.                                 halfSize = maxPlayersSize/2;
  10.                                 InitializePlayerNameList();
  11.                         }
  12.                         else
  13.                                 tno.Send("RequestUpdate", Target.Host, TNManager.playerID);
  14.  
  15.                         mRebuild = true;
  16.                 }
  17.         }
  18.  
  19. void PrintPlayerIDList() {
  20.                 GameChat gc = GameObject.Find("LobbyManager").GetComponent<GameChat>();
  21.                 string text = "";
  22.                 for(int i = 0; i < playersID.Length; i++)
  23.                         text += " "+playersID[i].ToString();
  24.                 gc.NotAllReady(text);
  25.         }
Adding this line of code prints out the array into my in-game chat. It prints 10 zeroes, which is the value of maxPlayersSize that was fed to it with no ID's yet assigned. Even so, I still get the error message when trying to assign a value to index 0. When I print it out after the ID is assigned to index 0, the host ID shows up in index 0 but the player visually shows up in index 1. All of this only happens in a built client though, never the editor. lol I can post the whole class of code if necessary.

EDIT: When adding code like so, I get the array error but also some weird print outs. It prints a 10, then a line of 10 zeroes, then a line of just a single 0. There should only be two things printing to the console and in the editor I get 10 on one line and 0 zeroes on the next, not the 3rd line of a zero.

  1. void OnNetworkJoinChannel (bool result, string message) {
  2.                 if(result) {
  3.                         if(TNManager.isHosting) {
  4.                                 GameChat gc = GameObject.Find("LobbyManager").GetComponent<GameChat>();
  5.                                 string text = maxPlayersSize.ToString();
  6.                                 gc.NotAllReady(text); //Prints a 10.
  7.                                 playersID = new int[maxPlayersSize];
  8.                                 playersTeam = new int[maxPlayersSize];
  9.                                 playersReady = new bool[maxPlayersSize];
  10.                                 PrintPlayerIDList(); //Prints a line of 10 zeroes.
  11.                                 playersID[0] = TNManager.hostID;
  12.                                 halfSize = maxPlayersSize/2;
  13.                                 InitializePlayerNameList();
  14.                         }
  15.                         else
  16.                                 tno.Send("RequestUpdate", Target.Host, TNManager.playerID);
  17.  
  18.                         mRebuild = true;
  19.                 }
  20.         }
Title: Re: Strange Build Behavior
Post by: ArenMook on January 30, 2014, 04:55:21 PM
Most obvious cause of something like that is having more than one script in the scene by mistake. Use NGUITools.GetHierarchy on the game object to get the path to it, that should help you track down where it's being called from that second time.
Title: Re: Strange Build Behavior
Post by: Katalyst on January 30, 2014, 05:56:36 PM
You were right. Another TNManager prefab had snuck into the scene as a stowaway on another object buried in the UI hierarchy. The error has been vanquished but the players being displayed in all the wrong spots only on built clients remains. I figured that error may have been the culprit but it wasn't.

It's quite baffling. The script just updates a list of labels with players name that it obtains from a list of player ID's that is synced across the network. For loops through it, 0-maxPlayerSize, and plops them on the screen. The built client has the list in the right order but seems to just shoot them on the screen wherever it pleases which should be out of the codes possibility. However, this doesn't appear to be related to TNet (this whole problem wasn't actually, sorry) so I'll take it to the Unity forums.

Thanks!