Author Topic: TNObject.RebuildMethodList ()  (Read 3527 times)

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
TNObject.RebuildMethodList ()
« on: April 30, 2015, 12:39:11 PM »
After updating Tnet and moving to Unity 5 I am getting this error.

NullReferenceException: Object reference not set to an instance of an object
TNObject.RebuildMethodList ()

What causes this and how do I fix it?

This is locking up my player controls particularly at SendMovements() and tno.SendQuickly.

  1. IEnumerator MyNetworkUpdate()
  2.         {
  3.                 for (;;) {
  4.                         yield return new WaitForSeconds (0.0333f);
  5.                         if (!useCar)
  6.                                 SendMovements();
  7.                         else
  8.                                 carControl.DriveCar (Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
  9.                                 //carControl.DriveCar (h,v);
  10.                                 //carControl.DriveCar (move.AxisX, move.AxisY);
  11. //                      Debug.Log ("send");
  12.                 }
  13.         }
  14.  
  15.         void SendMovements() {
  16.                 //if (Mathf.Abs (v) > .01f || Mathf.Abs (h) > .01f || Mathf.Abs (mX) > .01f || jump )
  17.                         tno.SendQuickly (9, Target.All, v, mX, h, jump);
  18.         }

Any idea?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNObject.RebuildMethodList ()
« Reply #1 on: April 30, 2015, 08:43:10 PM »
You will need to be more specific. On which line is it giving a null ref?

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNObject.RebuildMethodList ()
« Reply #2 on: May 01, 2015, 03:47:56 PM »
The error was at

tno.SendQuickly (9, Target.All, v, mX, h, jump);

This one I resolved by always having my input controls enabled.  While before I enabled it if tno.ismine.  Now, I just disable it at if !tno.ismine when a player spawns in.

I think someone mentioned before that tno.SendQuickly is supposed to default to tno.Send if there is no UDP.  It doesn't in this case, and it has never worked for me.  I had to change tno.SendQuickly to tno.Send for my controls to work again.

I also have another TNObject.RebuildMethodList () issue here with a Null reference.  Error as follows:

16777214 0 BackPackEnableCall
Object reference not set to an instance of an object
  at TNObject.RebuildMethodList () [0x00029] in /Users/PC 5/Assets/TNet/Client/TNObject.cs:424
  at TNObject.Execute (System.String funcName, System.Object[] parameters) [0x0002a] in /Users/vaughncarpenter/Documents/HorseArcherPC 5/Assets/TNet/Client/TNObject.cs:349
  at TNObject.FindAndExecute (UInt32 objID, System.String funcName, System.Object[] parameters) [0x00013] in /Users/PC 5/Assets/TNet/Client/TNObject.cs:392
  at TNManager.OnForwardedPacket (System.IO.BinaryReader reader) [0x00022] in /Users/vaughncarpenter/Documents/PC 5/Assets/TNet/Client/TNManager.cs:1180
UnityEngine.Debug:LogError(Object)
TNManager:OnForwardedPacket(BinaryReader) (at Assets/TNet/Client/TNManager.cs:1184)
TNet.GameClient:ProcessPacket(Buffer, IPEndPoint) (at Assets/TNet/Client/TNGameClient.cs:854)
TNet.GameClient:ProcessPackets() (at Assets/TNet/Client/TNGameClient.cs:791)
TNManager:Update() (at Assets/TNet/Client/TNManager.cs:1194)

The error message ends there.  As far as I can tell, it doesn't say where the null reference is.

The code in question, I suspect is here.  But, all my debug.Logs return a value, so I am not sure why there would be a null reference.

  1.         public void UpdateBackPack() {
  2.                 //string bckname = PlayerEquipment.currentBackPack.Name;
  3.                 Debug.Log (bckname);
  4.                 Debug.Log (tno);
  5.                 Debug.Log (backPacks.Count);
  6.  
  7.                 for (int loop = 0; loop < backPacks.Count; loop++ ) {
  8.                         Debug.Log (backPacks[loop]);
  9.                 }
  10.  
  11.                 if (tno.isMine)
  12.                         tno.Send ("BackPackEnableCall", TNet.Target.AllSaved, bckname);
  13.         }
  14.        
  15.         [RFC]
  16.         public void BackPackEnableCall(string bckname) {
  17. //              Debug.Log ("inside rfc");
  18.                 for (int loop = 0; loop < backPacks.Count; loop++ ) {
  19.                         backPacks[loop].SetActive (false);
  20.                 }
  21.  
  22.                 for (int loop2 = 0; loop2 < backPacks.Count; loop2++ ) {
  23.                         if (backPacks[loop2].name == bckname) {
  24.                                 backPacks[loop2].SetActive (true);
  25.                         }
  26.                 }
  27.         }

Thoughts?  I have been using tnet a long time.  Maybe something is conflicting with what worked before, but its hard to tell.  This used to work.  I haven't touched the above code in several months.

How do i troubleshoot error messages like the one I listed?

Thanks for the response.
« Last Edit: May 01, 2015, 04:06:58 PM by voncarp »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNObject.RebuildMethodList ()
« Reply #3 on: May 02, 2015, 10:18:35 PM »
Do you have more than one function with the same name? I recall that would cause issues when trying to find it by name afterwards. Our line numbers don't match so I can't pinpoint where the issue happens. TNObject's line 424 for me is inside FindAnExecute, not RebuildMethodList.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNObject.RebuildMethodList ()
« Reply #4 on: May 04, 2015, 12:46:04 PM »
I only have one.

Line 424 for me is:

System.Type type = mb.GetType();

  1.         void RebuildMethodList ()
  2.         {
  3.                 rebuildMethodList = false;
  4.                 mRFCs.Clear();
  5.                 MonoBehaviour[] mbs = GetComponentsInChildren<MonoBehaviour>(true);
  6.  
  7.                 for (int i = 0, imax = mbs.Length; i < imax; ++i)
  8.                 {
  9.                         MonoBehaviour mb = mbs[i];
  10.                         System.Type type = mb.GetType();
  11.  
  12.                         MethodInfo[] methods = type.GetMethods(
  13.  

On a new import of TNET in a new project that line would be line 417.

I do destroy some MonoBehaviours.  For instance, I have an LOD system, that the main player doesn't need to use on itself, so I destroy it. Is that the problem?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNObject.RebuildMethodList ()
« Reply #5 on: May 05, 2015, 10:52:02 PM »
Yes, that would be a problem. You are modifying a list that TNet is iterating through.

Wait until Start(), wait a frame, or just disable the component. Don't destroy it so early on.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNObject.RebuildMethodList ()
« Reply #6 on: May 06, 2015, 04:17:03 AM »
Yes, that would be a problem. You are modifying a list that TNet is iterating through.

Wait until Start(), wait a frame, or just disable the component. Don't destroy it so early on.

Fixed now.  :)