Author Topic: UIPanel content rendered at wrong coordinates  (Read 6981 times)

Devil_Inside

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
UIPanel content rendered at wrong coordinates
« 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).

kofight

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIPanel content rendered at wrong coordinates
« Reply #1 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel content rendered at wrong coordinates
« Reply #2 on: November 27, 2013, 12:56:22 AM »
Interesting... I was able to reproduce it, so I'm going to investigate it, thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel content rendered at wrong coordinates
« Reply #3 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]

Devil_Inside

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: UIPanel content rendered at wrong coordinates
« Reply #4 on: November 27, 2013, 06:06:54 AM »
I've updated and it works as expected!
Many thanks for the quick fix!