Author Topic: Glyph corruption issue in a dynamic UILabel: anyone else?  (Read 5472 times)

jchowdown

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Glyph corruption issue in a dynamic UILabel: anyone else?
« on: January 27, 2014, 02:14:36 PM »
Hi, I'm running into a weird problem with my glyphs showing incorrect textures for a split second. Here's what I'm doing:
1) I have a UI scene with different objects representing different dialogs. Only one of these is active at any time
2) My main menu dialog displays fine when I load the game.
3) I display a submenu (an alternate dialog) and at the same time I setActive(false) on the main dialog. Everything in this sub dialog display fine as well
4) If I deactivate this submenu and reactivate the main menu, the strings in my main menu buttons look incorrect for a split second. They appear to be mapped incorrectly. It spends 2-3 frames in this state (each frame changes the mapping, giving the strings a Matrix-like fade-in effect) and eventually displays the right thing by frame 4 (after reactivating this dialog)
5) The corruption stops happening when I repeat steps 3 and 4. (ie the corruption only happens the first time I do steps 3 and 4 after I launch the app cleanly)

Now, this text corruption looks exactly like a UV issue with bitmapped fonts but all my uilabels use a dynamic font. Another clue is that this doesn't happen in the editor but only on my iPad 4. Has anyone seen this before?

Thanks in advance,
Jeff

ryan

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 90
    • View Profile
Re: Glyph corruption issue in a dynamic UILabel: anyone else?
« Reply #1 on: January 27, 2014, 04:55:23 PM »
This essentially is a UV issue.  As characters are added to the dynamically generated texture, Unity will occasionally need to rebuild the entire texture to make room for more characters.  It may make the texture bigger, or it may remove unused characters, but in either case the UVs of each individual character are changing.

Unity provides an API to notify applications when this rebuild is happening, and NGUI listens to those events and flags affected labels to be rebuilt the next time UIPanel's LateUpdate is run.  However, if you manage to instantiate some UILabels or otherwise cause new characters to be rendered for a dynamic font after UIPanel.LateUpdate, but before the end of the frame, then NGUI doesn't have a chance to respond until the next frame.  We've run into this problem once or twice.  It becomes especially apparent when doing blocking operations that cause a long delay between frames.  You don't notice this in the editor because (I think) the editor keeps the dynamic texture around between invocations of your code, so it's likely already sized large enough that a rebuild isn't necessary.

In our case, we were instantiating some UI prefabs while handling a network response from a coroutine.  Somehow the Start function was being called on those instances after UIPanel.LateUpdate but still in the same frame.  We managed to work around it by having the coroutine set a flag that we waited until the next Update to act on, so our prefabs were instantiated at a different time.  Michael might be able to address this in NGUI somehow, but it's probably not trivial to rebuild all of the affected panels outside of LateUpdate.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Glyph corruption issue in a dynamic UILabel: anyone else?
« Reply #2 on: January 27, 2014, 07:02:24 PM »
Yeah it's one of those issues that keeps cropping up every so often. Unity's API for updating dynamic fonts hasn't been thought out thoroughly. Ideally there would be a way to say, "font, these are the characters I need, in this font size. NEVER release them!". Instead Unity seems to freely release characters that haven't been requested recently... I bet I can hack it somehow by force-requesting all labels at once, but it will slow everything down. I posted a script in the Useful Stuff sticky post about how to force-request a string of characters in advance that may be helpful to you.

jchowdown

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Glyph corruption issue in a dynamic UILabel: anyone else?
« Reply #3 on: January 29, 2014, 03:19:43 AM »
Thanks gents, it sounds like a mild workaround is in order but it's not the end of the world.

pyamamoto

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Glyph corruption issue in a dynamic UILabel: anyone else?
« Reply #4 on: July 08, 2014, 09:43:55 PM »
Is this issue actively monitored wrt Unity status or is there a ticket open with Unity that I could refer to when communicating with them about this issue?

While we have tried keeping up with particularly bad situations by using the workaround we do still experience this often enough to be disconcerting from a user experience point of view.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Glyph corruption issue in a dynamic UILabel: anyone else?
« Reply #5 on: July 09, 2014, 04:06:04 PM »
I honestly don't know if there is an open ticket or not. It's hard to reproduce reliably too, so I wouldn't be surprised if they tried and gave up. It's the worst kind of issue.

pyamamoto

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Glyph corruption issue in a dynamic UILabel: anyone else?
« Reply #6 on: July 09, 2014, 04:09:55 PM »
I meant whether you personally opened a bug. We have several open issues with Unity at the moment and this issue does fairly consistently reproduce itself on certain devices (we have loading screen text updates that will corrupt for example), was mainly looking for references before opening our own ticket for this specific issue.

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Glyph corruption issue in a dynamic UILabel: anyone else?
« Reply #7 on: July 09, 2014, 04:56:02 PM »
I mentioned this problem to the person who wrote the feature back when I worked at Unity, but he didn't know what may cause it. I didn't submit any bug requests at the time. Others may have though (and I encouraged them to do so).

makeshiftwings

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Glyph corruption issue in a dynamic UILabel: anyone else?
« Reply #8 on: July 17, 2014, 12:42:33 AM »
I'm getting this pretty consistently after doing a Google Play Billing purchase.  When the Android purchase window pops up it puts the app into pause mode but leaves it open in the background, then when the purchase window closes it resumes the Unity app and messes up the dynamic fonts if I try to set any labels soon after that, and then that font remains corrupted until I kill the app.