Author Topic: [3.6.9] NullReferenceException in UIToggle.Set - UIToogle.cs:249 line  (Read 2969 times)

Presario

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Hi there,

Some time I'm getting a NullReferenceException at UIToggle.Set - UIToogle.cs:249 line, for example:
  1. NullReferenceException: Object reference not set to an instance of an object
  2. UIToggle.Set (Boolean state) (at Assets/Common/ThirdParty/NGUI/Scripts/Interaction/UIToggle.cs:249)
  3. UIToggle.set_value (Boolean value) (at Assets/Common/ThirdParty/NGUI/Scripts/Interaction/UIToggle.cs:98)
  4. ActivityController.Reset (Boolean show) (at Assets/Game/Scripts/ActivityController.cs:121)
  5. GameStateController+<Reset>c__Iterator44.MoveNext () (at Assets/Game/Scripts/GameStateController.cs:267)

The reson for that is from code below  aa @ UIToogle.cs:249 line  can be null some time
  1. ...
  2.                         // Play the checkmark animation
  3.                         if (activeAnimation != null)
  4.                         {
  5.                                 ActiveAnimation aa = ActiveAnimation.Play(activeAnimation, null,
  6.                                         state ? Direction.Forward : Direction.Reverse,
  7.                                         EnableCondition.IgnoreDisabledState,
  8.                                         DisableCondition.DoNotDisable);
  9.                                 if (instantTween || !NGUITools.GetActive(this)) aa.Finish(); /// <===== aa is null causing NullReferenceException
  10.                         }
  11. ...
  12.  

so fix is simple:
  1. ...
  2.                         // Play the checkmark animation
  3.                         if (activeAnimation != null)
  4.                         {
  5.                                 ActiveAnimation aa = ActiveAnimation.Play(activeAnimation, null,
  6.                                         state ? Direction.Forward : Direction.Reverse,
  7.                                         EnableCondition.IgnoreDisabledState,
  8.                                         DisableCondition.DoNotDisable);
  9.                                 if (aa != null && ( instantTween || !NGUITools.GetActive(this))) aa.Finish(); /// <=== added null check for aa
  10.                         }
  11. ...
  12.  


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [3.6.9] NullReferenceException in UIToggle.Set - UIToogle.cs:249 line
« Reply #1 on: August 13, 2014, 08:10:17 AM »
Makes sense, thanks.