Author Topic: Dynamic font randomly don't show properly  (Read 64815 times)

eddieB

  • Guest
Dynamic font randomly don't show properly
« on: May 27, 2013, 02:57:18 AM »
hi everyone

i'm using UI label with dynamic font (japans font), sometime it show well but suddenly the phrases are broken and somme letter are missing.
( Android xperia)

http://gyazo.com/3380f5895829f231575ae11c6fb1eefe
http://gyazo.com/b4d4e10cb78a2c0b84d89c7c7c64fdb6

Uilabel are not on the same z than the other atlases as recommended.

 have you any idea of how to fix this problem?
« Last Edit: May 27, 2013, 03:03:00 AM by eddieB »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic font randomly don't show properly
« Reply #1 on: May 27, 2013, 11:31:39 AM »
When the texture's dimensions change, NGUI marks the font as dirty, which in turn forces all labels to refresh their content, which should cause everything to update correctly. I've seen reports that this is not always the case however, and you are likely encountering this issue. Based on another thread from last week this issue lies within Unity, but you are welcome to offer a second opinion. The function that gets called when the font changes is UIFont.OnFontChanged -- line 1057 of UIFont.cs. You can try adding a NGUITools.Broadcast("Refresh"); right after MarkAsChanged() there to see if that helps.

eddieB

  • Guest
Re: Dynamic font randomly don't show properly
« Reply #2 on: May 28, 2013, 03:14:56 AM »
thanks for your answer but this fix doesn't work.

we add some test with a guy button to refresh when we want but it seems to not working when we use the NGUITools.Broadcast("Refresh");

We are using a japanese font in a big scale like 40 could it be the problem?
the texture is not refreshing well on android devices and the texture size of the dynamic font overflow the 2048x2048 ? (the bug always appear after 5 minutes of using the apply). japanese font have a lot of characters so it could be the problem.

we add test on editor and the refresh is working well so the texture size is not over 1024x1024.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic font randomly don't show properly
« Reply #3 on: May 28, 2013, 02:57:09 PM »
Wait... did you say your font texture size exceeds 2048x2048? Majority of mobile devices can't support texture sizes above 2k by 2k.

eddieB

  • Guest
Re: Dynamic font randomly don't show properly
« Reply #4 on: May 28, 2013, 07:42:11 PM »
it could be a problem.

but after further test it look like it came from unity the texture didn't exceeds 2048x2048.
i also test it with smaller font.

sometime during the refreshing of the font some letters are missing on the dynamic font texture.
« Last Edit: May 29, 2013, 12:45:58 AM by eddieB »

haoxiucai001

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Dynamic font randomly don't show properly
« Reply #5 on: May 28, 2013, 08:19:07 PM »
用了这个方法了,可是不行。
wait,The question remains

eddieB

  • Guest
Re: Dynamic font randomly don't show properly
« Reply #6 on: June 03, 2013, 03:14:49 AM »
we find a little hack to fix the problem.

it's seems like the bug is random, but sometimes the dynamic font code request some character that are not in the texture, and unity code answer to this request like they are already on the texture. certanly a texture saving fail on some hardware.

exemple
  is "a" is in the texture ?  --> yes    (but if we look at the texture there is no a)

how we fix it (not very clean but it work).

when the page finish building (dynamic build of list from servers) so every text is on the UIlabel we call two function of the UIfont after waiting some frames to avoid problems.

ClearCharacterInfo(); (make unity rebuild the font)
MarkAsDirty();

Edit we add this font ion into UiFont.cs
  1. public void ClearCharacterInfo() {
  2.                 mDynamicFont.characterInfo = null;
  3.         }
  4.  

this option may use some memory, but it is the safer way to assure that the text will be shown well on the devices who are concerned by this bug.
« Last Edit: June 03, 2013, 03:38:44 AM by eddieB »

raon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Dynamic font randomly don't show properly
« Reply #7 on: June 03, 2013, 03:31:00 AM »
ClearCharacterInfo(); (make unity rebuild the font)
MarkAsDirty();

Hi, eddieB.

I have same problem.

What is ClearCharacterInfo(); ?
My UIFont.cs not exists function.

Could you tell me what is?

eddieB

  • Guest
Re: Dynamic font randomly don't show properly
« Reply #8 on: June 03, 2013, 03:36:22 AM »
sorry i foot to speak about the function that we add in UIFont

   public void ClearCharacterInfo() {
      mDynamicFont.characterInfo = null;
   }


raon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Dynamic font randomly don't show properly
« Reply #9 on: June 03, 2013, 03:38:10 AM »
Thanks eddieB :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic font randomly don't show properly
« Reply #10 on: June 03, 2013, 09:27:23 AM »
Thanks for debugging this one, eddieB. It's a weird bug, as it seems to only affect certain devices. I can't reproduce it at all on mine, which makes it difficult to fix.

So just to clarify, to work around it you request the characters, then wait, or do you clear the character info and then request the new characters?

raon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Dynamic font randomly don't show properly
« Reply #11 on: June 03, 2013, 08:40:13 PM »
Hi, ArenMook and eddieB

The problem is not be resolved after call ClearCharacterInfo.

It's more happened to break letter.

I guess that it's happened to device in screen dpi 320. (xhdpi)

:'(

eddieB

  • Guest
Re: Dynamic font randomly don't show properly
« Reply #12 on: June 03, 2013, 09:54:33 PM »

@Arenmook
it's very difficult to reproduce it only affect some android device for our project after navigation on page with a lot of text and item list added with instantiate.

we can't know by script if the dynamic system is broken an don't include some character.
so by our safety we use a safety, when the page display is finished we wait 3 frames (we use other frame to recalculate some position on menu) and clean the character info so it refresh everything when the MarkAsDirty() run.




eddieB

  • Guest
Re: Dynamic font randomly don't show properly
« Reply #13 on: June 03, 2013, 10:00:45 PM »
@raon

do you waiting some frame? and clear character and use the MarkAsDirty() after ?
make sure that there isn't any UiFont calculation after  clear characterInfo.

this bug fix works on our project but maybe it's not the better for everyone. 
the bug also appending a lot if you are making a lot of font.

for example if you are making the arialFont 24px,12px,30px
on our project we made a font of 40px and change the scale of label of the desired scale.
 
 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic font randomly don't show properly
« Reply #14 on: June 03, 2013, 10:02:02 PM »
Alright, I'm going to dig into the C++ back-end code for this if I get some time and see if I can figure out what's breaking it. It would be so much easier if I could just use FreeType directly... but I can't do that at run-time.