Author Topic: Critical bug when changing font size in NGUI 3.9 with Unity 4.6.x  (Read 8124 times)

Lenius

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Critical bug when changing font size in NGUI 3.9 with Unity 4.6.x
« on: September 30, 2015, 07:37:56 AM »
Hi. I'm using NGUI 3.9.3 with Unity 4.6.x and I encountered a bug that will crash the project. Here is how to reproduce it:
When you change the font size rapidly of a UILabel in the inspector, there is a very high possibility (nearly 100%) that NGUI will mess the font used by itself. E.g. in the following screenshot(2.png), if you press and hold the left mouse button and move left and right rapidly, it's almost certain that the font will broke, causing the error in the following screenshots(3.png and 4.png).

Note1: The error will only be cleared if you re-open Unity, which is very annoying.
Note2: The bug is present in all the versions of NGUI after 3.9.0, including the latest version. I really hope this get fixed soon. Thanks.
« Last Edit: September 30, 2015, 07:57:10 AM by Lenius »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Critical bug when changing font size in NGUI 3.9 with Unity 4.6.x
« Reply #1 on: October 01, 2015, 01:52:02 AM »
Try this...

1. Make UIPanel.FillDrawCall function public.

2. Change UILabel.OnFontChanged to this:
  1.         static void OnFontChanged (Font font)
  2.         {
  3.                 for (int i = 0; i < mList.size; ++i)
  4.                 {
  5.                         UILabel lbl = mList[i];
  6.  
  7.                         if (lbl != null)
  8.                         {
  9.                                 Font fnt = lbl.trueTypeFont;
  10.  
  11.                                 if (fnt == font)
  12.                                 {
  13.                                         fnt.RequestCharactersInTexture(lbl.mText, lbl.mFinalFontSize, lbl.mFontStyle);
  14.                                         lbl.MarkAsChanged();
  15.  
  16.                                         if (lbl.panel == null)
  17.                                                 lbl.CreatePanel();
  18.  
  19.                                         if (mTempDrawcalls == null)
  20.                                                 mTempDrawcalls = new List<UIDrawCall>();
  21.  
  22.                                         if (lbl.drawCall != null && !mTempDrawcalls.Contains(lbl.drawCall))
  23.                                                 mTempDrawcalls.Add(lbl.drawCall);
  24.                                 }
  25.                         }
  26.                 }
  27.  
  28.                 if (mTempDrawcalls != null)
  29.                 {
  30.                         for (int i = 0, imax = mTempDrawcalls.Count; i < imax; ++i)
  31.                         {
  32.                                 UIDrawCall dc = mTempDrawcalls[i];
  33.                                 if (dc.panel != null) dc.panel.FillDrawCall(dc);
  34.                         }
  35.                         mTempDrawcalls.Clear();
  36.                 }
  37.         }
  38.  
  39.         static List<UIDrawCall> mTempDrawcalls;

poolts

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: Critical bug when changing font size in NGUI 3.9 with Unity 4.6.x
« Reply #2 on: October 03, 2015, 10:25:16 AM »
Will this fix be included in the next version of NGUI?  :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Critical bug when changing font size in NGUI 3.9 with Unity 4.6.x
« Reply #3 on: October 03, 2015, 06:23:34 PM »
Yup.