Author Topic: "Nested" toggles cause a problem when hiding children  (Read 1731 times)

bkevelham

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 11
    • View Profile
    • Personal Website
"Nested" toggles cause a problem when hiding children
« on: October 21, 2013, 08:25:29 AM »
In our UI we have a set of UIToggles, let's say 2 of them, which show or hide sub-options. They are in their own group. So enabling one will disable the other.

Enabling a certain toggle will show a kind of sub-ui. This part of the UI also has UIToggles (in their own group). The "nesting" I speak of here is not a physical parent-child relationship of these toggles. Just that some parts are controlled (hidden/shown) by the "parent" UIToggles.

The issue I'm running into is with UIToggle's Set(bool state). When I click on a parent check-box, it will set that one as checked. And it will set the other one to be unchecked. Doing so will trigger a routine to hide the children UIToggles.

This leads to a nullpointer exception in the following section within UIToggle (Line 177 onward):

  1. for (int i = 0, imax = list.size; i < imax; ++i)
  2. {
  3.         UIToggle cb = list[i];
  4.         if (cb != this && cb.group == group) cb.Set(false);
  5. }

The case is that imax is initialized to a value where all UIToggles were still visible. Parents and the active parent's children toggles included. However, the updates cause the list to be modified (somehow, I'm unclear on the call order) leaving it with less items (after all, some of them were made invisible). So list.size is lower inside the loop than the value imax was initialized to. And this will cause a problem with cb being null at some point.

I fear the answer is going to point at me, but could this be a problem/unforeseen circumstance on the NGUI side of the equation. Or am I simply trying to do something I really shouldn't do?

If necessary I could try and extract a simple stand-alone example, should the description not be clear.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "Nested" toggles cause a problem when hiding children
« Reply #1 on: October 21, 2013, 01:42:28 PM »
Known issue, addressed in 3.0.3.

bkevelham

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 11
    • View Profile
    • Personal Website
Re: "Nested" toggles cause a problem when hiding children
« Reply #2 on: October 22, 2013, 01:24:44 AM »
Wonderful. Other than that, stepping to 3.0 was trivial. A job well done.