Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Devil_Inside on November 26, 2013, 06:30:43 PM

Title: UIPanel content rendered at wrong coordinates
Post by: Devil_Inside on November 26, 2013, 06:30:43 PM
I've encountered some strange behaviour in the UIPanel. Whenever I create two panels and add widgets to both, the widgets that are added to the second panel are rendered at the wrong position. This happens either the moment I create them, or after panels alpha is set to 0 and then back to 1.
To reproduce this bug:
1. Create a 2D UI from the NGUI menu.
2. Rename Panel to Panel1
2. Duplicate Panel1 and rename it to Panel2
3. Move Panel1 100px to the left
3. Move Panel2 100px to the right
4. Drag a Wooden -> Control - Colored Button into the Panel1 (the button is added and rendered as expected)
5. Drag a Wooden -> Control - Colored Button into the Panel2. (button gizmo and collision box is added to the right position, but the actual button is rendered at the position of the button in Panel1)

Changing the Panel2 order, or disabling and re-enabling the panel, or running the game seems to fix it. But if you change the panels alpha to 0 and then back to 1, it gets broken again. The gizmo is drawn at the right position, while the button is rendered at the position of button in Panel1 (or the center of the screen).
Title: Re: UIPanel content rendered at wrong coordinates
Post by: kofight on November 26, 2013, 09:01:34 PM
It's great that you find the way to reproduce it, I met the same bug. And I think most of the bugs reported for 3.06 f2 come from that.
Title: Re: UIPanel content rendered at wrong coordinates
Post by: ArenMook on November 27, 2013, 12:56:22 AM
Interesting... I was able to reproduce it, so I'm going to investigate it, thanks!
Title: Re: UIPanel content rendered at wrong coordinates
Post by: ArenMook on November 27, 2013, 01:19:54 AM
Alright, found the issue and here is the fix. Replace UIPanel.InsertWidget function with the following:
  1.         static public UIDrawCall InsertWidget (UIWidget w)
  2.         {
  3.                 UIPanel p = w.panel;
  4.                 if (p == null) return null;
  5.                 Material mat = w.material;
  6.                 int depth = w.raycastDepth;
  7.                 BetterList<UIDrawCall> dcs = UIDrawCall.activeList;
  8.  
  9.                 for (int i = 0; i < dcs.size; ++i)
  10.                 {
  11.                         UIDrawCall dc = dcs.buffer[i];
  12.                         if (dc.manager != p) continue;
  13.                         int dcStart = (i == 0) ? int.MinValue : dcs.buffer[i-1].depthEnd + 1;
  14.                         int dcEnd = (i + 1 == dcs.size) ? int.MaxValue : dcs.buffer[i+1].depthStart - 1;
  15.                        
  16.                         if (dcStart <= depth && dcEnd >= depth)
  17.                         {
  18.                                 if (dc.baseMaterial == mat)
  19.                                 {
  20.                                         if (w.isVisible && w.hasVertices)
  21.                                         {
  22.                                                 w.drawCall = dc;
  23.                                                 dc.isDirty = true;
  24.                                                 return dc;
  25.                                         }
  26.                                 }
  27.                                 else mRebuild = true;
  28.                                 return null;
  29.                         }
  30.                 }
  31.                 mRebuild = true;
  32.                 return null;
  33.         }[code]
Title: Re: UIPanel content rendered at wrong coordinates
Post by: Devil_Inside on November 27, 2013, 06:06:54 AM
I've updated and it works as expected!
Many thanks for the quick fix!