Author Topic: NGUI 3.0.8 fx2 null reference excpetion in UIDrawCall with fix  (Read 5131 times)

kasparlund

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
NGUI 3.0.8 fx2 null reference excpetion in UIDrawCall with fix
« on: January 04, 2014, 01:09:02 PM »
I got null reference on app termination i UIPanle and had to make the following fix

The fix is to check for "dc!=null" in ClearAll,  ReleaseAll, Destroy:
 
   static public void ClearAll ()
   {
      bool playing = Application.isPlaying;

      for (int i = mActiveList.size; i > 0; )
      {
         UIDrawCall dc = mActiveList[--i];
         if( dc!=null ){
            if (playing) NGUITools.SetActive(dc.gameObject, false);
            else NGUITools.DestroyImmediate(dc.gameObject);
         }
      }
      mActiveList.Clear();
   }

   static public void ReleaseAll ()
   {
      ClearAll();

      for (int i = mInactiveList.size; i > 0; )
      {
         UIDrawCall dc = mInactiveList[--i];
         if( dc!=null )
            NGUITools.DestroyImmediate(dc.gameObject);
      }
      mInactiveList.Clear();
   }

   static public void Destroy (UIDrawCall dc)
   {
      if (Application.isPlaying && dc!=null )
      {
         if (mActiveList.Remove(dc))
         {
               NGUITools.SetActive(dc.gameObject, false);
               mInactiveList.Add(dc);
         }
      }
      else if( dc!=null )
      {
         mActiveList.Remove(dc);
         NGUITools.DestroyImmediate(dc.gameObject);
      }
   }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0.8 fx2 null reference excpetion in UIDrawCall with fix
« Reply #1 on: January 04, 2014, 01:15:24 PM »
How did you even get to the state where draw call is null? What destroyed it? Only UIDrawCall is capable of destroying draw calls, and it only always removes the draw call from the active and inactive lists.

Dust

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: NGUI 3.0.8 fx2 null reference excpetion in UIDrawCall with fix
« Reply #2 on: January 07, 2014, 03:56:25 PM »
How did you even get to the state where draw call is null? What destroyed it? Only UIDrawCall is capable of destroying draw calls, and it only always removes the draw call from the active and inactive lists.

I want to say I just ran into this issue and all I did was upgrade from 3.0.8 f6 to f7.  Unity 4.2.2 and device is a Nexus 5 running 4.4.2

This happens when i use the android back button to quit the app.

Unity Log Below:

I get the error itself regarding the NullRef 4 times
  1. I/Unity   (24487): time to quit..
  2. I/Unity   (24487): windowFocusChanged: false
  3. I/Unity   (24487): onPause
  4. I/Unity   (24487): NullReferenceException
  5. I/Unity   (24487):   at UnityEngine.Component.get_gameObject () [0x00000] in <filename unknown>:0
  6. I/Unity   (24487):   at UIDrawCall.Destroy (.UIDrawCall dc) [0x0000a] in C:\Projects\GCSlotzMW\Assets\NGUI\Scripts\Internal\UIDrawCall.cs:693
  7. I/Unity   (24487):   at UIPanel.OnDisable () [0x00007] in C:\Projects\GCSlotzMW\Assets\NGUI\Scripts\UI\UIPanel.cs:712

If i modify the Destroy() part to check for dc != null then i end up with:
  1. I/Unity   (24816): time to quit..
  2. I/Unity   (24816): windowFocusChanged: false
  3. I/Unity   (24816): onPause
  4. I/Unity   (24816): NullReferenceException
  5. I/Unity   (24816):   at UnityEngine.Component.get_gameObject () [0x00000] in <filename unknown>:0
  6. I/Unity   (24816):   at UIDrawCall.ClearAll () [0x00026] in C:\Projects\GCSlotzMW\Assets\NGUI\Scripts\Internal\UIDrawCall.cs:651
  7. I/Unity   (24816):   at UIDrawCall.ReleaseAll () [0x00000] in C:\Projects\GCSlotzMW\Assets\NGUI\Scripts\Internal\UIDrawCall.cs:663
  8. I/Unity   (24816):   at UIPanel.OnDisable () [0x00054] in C:\Projects\GCSlotzMW\Assets\NGUI\Scripts\UI\UIPanel.cs:718

If i then modify the ClearAll() part to check for dc != null then i end up with:
  1. I/Unity   (25112): time to quit..
  2. I/Unity   (25112): windowFocusChanged: false
  3. I/Unity   (25112): onPause
  4. I/Unity   (25112): NullReferenceException
  5. I/Unity   (25112):   at UnityEngine.Component.get_gameObject () [0x00000] in <filename unknown>:0
  6. I/Unity   (25112):   at UIDrawCall.ReleaseAll () [0x00025] in C:\Projects\GCSlotzMW\Assets\NGUI\Scripts\Internal\UIDrawCall.cs:671
  7. I/Unity   (25112):   at UIPanel.OnDisable () [0x00054] in C:\Projects\GCSlotzMW\Assets\NGUI\Scripts\UI\UIPanel.cs:718

And then we modify the ReleaseAll() part to check for dc != null and i end up with no errors:

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0.8 fx2 null reference excpetion in UIDrawCall with fix
« Reply #3 on: January 08, 2014, 01:16:22 PM »
Did you follow the NGUI upgrade instructions? I can see something like this happening if you didn't.

Restart Unity. Does it still occur?