Author Topic: [bug] UIToggle.list  (Read 2015 times)

7realm

  • Guest
[bug] UIToggle.list
« on: October 07, 2013, 11:13:39 PM »
I got a NPE for UIToggle when I updated to 3.0.0 version, but first I made only dirty fix for it. But later I found its reason. When we iterate through UIToggle.list to uncheck all checkbox of same group, we do not count that unchecking checkbox can actually change UIToggle.list size. In my situation I had 3 UIToggles as tab buttons and I had few UIToggles that where only in one tab content, which was controlled by one of top level checkboxes. Because in the loop where we look for checkbox to uncheck it, we store their count before loop, the list itself is modified, but count - is not. So if we still try to iterate to the end of list, BetterList will return null checkboxes.

If you need more details about this, please let me know.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [bug] UIToggle.list
« Reply #1 on: October 08, 2013, 01:09:20 AM »
Unchecking checkboxes won't change UIToggle.list. Activating and deactivating UIToggles will. What are you using UIToggle.list for?

7realm

  • Guest
Re: [bug] UIToggle.list
« Reply #2 on: October 08, 2013, 01:44:40 AM »
I have tabs(checkboxes in one group) and tab content panels. Each tab is check box that controls its panel by activating and deactivating it. On one tab content panel I again have few checkboxes, so when I deactivate it, this checkboxes are deactivated.

So I open this window and see tabs buttons, for example first tab is checked. On its content there are another checkboxes. When I hit second tab, first tab is deactivated, and it automatically deactivates its content (with checkboxes). At this point I get NPE at line 180 of UIToggle.cs, cb is null
  1. // Uncheck all other toggles
  2.                         if (group != 0 && state)
  3.                         {
  4.                                 for (int i = 0, imax = list.size; i < imax; ++i)
  5.                                 {
  6.                                         UIToggle cb = list[i];
  7.                                         if (cb != this && cb.group == group) cb.Set(false);
  8.                                 }
  9.                         }

this happens that for example in first iteration of loop, we deactivated some other checkboxes via cb.Set(false), and they are not in list already. But imaxthat  you calculated before iterating the list contains old value, so when I access element beyond the list it returns null and that is why cb can be null.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [bug] UIToggle.list
« Reply #3 on: October 08, 2013, 01:46:40 AM »
Ah, I see. I'll add a check for that, thanks.