Author Topic: Problems about Dynamic font support for NGUI  (Read 12649 times)

zhaoway

  • Guest
Problems about Dynamic font support for NGUI
« on: July 10, 2013, 03:50:46 AM »
   When  using  Dynamic font feature of NGUI, I found some problems. First if you make two UIFont use the same font, the display of text may be corrupt.  I notice the follow code at UIFont.cs:
        dynamicFont.textureRebuildCallback = OnFontChanged;
        dynamicFont.RequestCharactersInTexture(text, dynamicFontSize, dynamicFontStyle);
        dynamicFont.textureRebuildCallback = null;   

  The UIFont  listen rebuild callback of dynamic font only when request characters by itself, so it will be notified by others. It is why we get currupt text display.  You can also make this bug if let 3D Text and UIFont use the same dynamic font.

The next bugs is that some characters may be display as blank, which is common thing at andorid phone with qualcomm chips.  As you known, I need display chinese characters, so Dynamic font feature is valuable.  But this bugs is too often at Xiaomi phone, I study the code of NGUI and unity manual. I notice that the current dynamic font  implementation is slow, which repeat  request characters. If I put more UILable at scence and change it content, the time lag is noticable. So, I modify code,  if OnFontChanged is called, NOT need to request characters. Instead, we create UIFontManager request all UILabel text at LateUpdate.
    After we do this, One TTF font never produce this bugs, but others fonts also, which make me confuse. I do such a test:  alway show a 3D text gameobject with text of all UILable at scene,  and I see that 3D text gameobject  may  lose some characters.
    I come to a conclusion: this bug came from low performance of phone.  Dynamic font need produce character image from ture type font file, which cost too much CPU. If the request characters cannot be done, Unity will return blank for some characters. For chinese characters and other asia characters, use dynamic font feature of unity at phone is unstable.
    Maybe there are some tricks to work around this unity bugs: never request too many characters  at one frame, your should let UIlabel only  to draw its text after have requested its characters. This make code more complex!


Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
Re: Problems about Dynamic font support for NGUI
« Reply #1 on: July 10, 2013, 12:38:28 PM »
Could you make a non-NGUI test case of this problem (don't use any NGUI stuff) and then submit a bug report via Unity from within your test case project so that Unity can fix this bug with the dynamic font request system? It has been plaguing a lot of people for a long time and no one has been able to submit a test case that can display the problem properly thus has never been fixed in Unity.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problems about Dynamic font support for NGUI
« Reply #2 on: July 10, 2013, 01:05:39 PM »
Yeah a non-NGUI example of this problem submitted in a bug report will get it fixed. I talked to the person responsible for this feature and he simply doesn't have a solid bug report to go by.

zhaoway

  • Guest
Re: Problems about Dynamic font support for NGUI
« Reply #3 on: July 12, 2013, 07:41:46 AM »

   Sorry, I try to use 3D text to produce this bugs without NGUI, but it run well. And in order to prove where is bugs, I make another test.  Use one 3D text show all of content of my NGUI labels in our project ( which take the same TTF font ), and I see such result: if ngui labels lost some charaters, the 3D text follow them. So I conclude that the texture of dynamic font lost these characters, which should be a bug  of unity.

zhaoway

  • Guest
Re: Problems about Dynamic font support for NGUI
« Reply #4 on: July 13, 2013, 02:37:18 AM »
hi,
    I have made a simple project with NGUI to produce this bugs. It include:
         a 3D text with a 3d camera ,  a NGUI  label with  it 2d camera .  3D text and NGUI use the same TTF font with the same size, and 3d text always display the same string of label.  Wen users tourch screen , program randomly change label's text.

   There is a key point: we use InvokeRepeating method  to implement a timer which  add one character to label at one interval ( 0.1s ). I think  others can  produce this bug easyly on andorid phone.

lenneth78

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Problems about Dynamic font support for NGUI
« Reply #5 on: October 25, 2013, 10:25:22 AM »
Hi Aren,

We have the same bug here, labels lose their width and height limit, letters disappear and sometimes labels disappear completely.
We use NGUI 2.7.0.
This bugs is hard to fix because, he is randomely.

thx


demid

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Problems about Dynamic font support for NGUI
« Reply #6 on: January 14, 2014, 02:48:25 PM »
Hello guys!
I'm experiencing the same bug with NGUI 2.7.0 which is unfortunately hard to reproduce. Did anyone found a workaround for this problem so far? Maybe there are facts proving that NGUI 3.x fixed this (it's rather hard and bugprone for me to migrate a project to 3.x)?
Thanks for your responses!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problems about Dynamic font support for NGUI
« Reply #7 on: January 14, 2014, 09:29:40 PM »
There was a similar post about this just yesterday where I posted a script that will request all characters in advance.

demid

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Problems about Dynamic font support for NGUI
« Reply #8 on: January 15, 2014, 03:55:56 AM »
For all who are experiencing the same trouble here is the mentioned post: http://www.tasharen.com/forum/index.php?topic=7512.msg35539#msg35539 (there is a fact that a bug still present in NGUI 3.0.8 )
and finally this is the script which should do the trick (didn't try it myself yet): http://www.tasharen.com/forum/index.php?topic=7399.msg34945#msg34945

I'm using asian fonts (Chinese, Japanese and Korean) also and this exact script won't help me. There are about 2300 english words in my UI and most likely a big amount of different hieroglyphs (did not count yet) mixed with english letters. So it might be impossible to request all characters on the Android platform. I'll come back here with my solution later.

EDIT: In my specific case all used unique characters in all labels fit into 2K atlas so the solution is to gather all texts manually and call RequestCharactersInTexture() with this text upon locale change.
« Last Edit: February 10, 2014, 01:18:45 PM by demid »