Author Topic: Font scramble on save bug?  (Read 5796 times)

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Font scramble on save bug?
« on: October 16, 2013, 11:52:31 AM »
An artist and I are collaborating on a project using SVN for our project management.  He has delivered an atlas to me with some sprites and 2 fonts in it.  We have been working on things for a few weeks since then and then one night just one of the two fonts got completely garbled after a small (seemingly unrated change).  It looks like the data about where to go find each character is messed up and showing parts of seemingly random sprites in the same atlas.  Here is where it gets really funny: Neither one of us made a change to the font or the atlas.  It appears to have done this on save of the project (after I moved some buttons around in the scene) and checked it in (not knowing the font was messed up).

More strangeness:
He SVN updates to the change I made doesn't get the strange font effect.  It only happens to my local copy of the project.  I have deleted the entire project and checked out a clean project and I still have the same font problem.  I can SVN revert to the revision before the font problem happened and it goes away.  When I update to the next revision (the one with my scene change in it) the font problem comes back.  The only change was to the scene (and a few un-related cs files) on this revision.

Any thoughts about what in the world could be causing this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font scramble on save bug?
« Reply #1 on: October 16, 2013, 12:57:30 PM »
Can't say I have a suggestion on this one.

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Font scramble on save bug?
« Reply #2 on: October 17, 2013, 05:57:58 PM »
OK, after fooling around with this for many hours, meticulously reverting and updating to specific revisions of my scene that went bad... I have found a very data point.

First an additional note about how the scene is set up.  There is a panel that dynamically loads a prefab that has this font used in a label on it.  This font is messed up in the current revision of the scene.

Working with the scene AFTER it became bad (showing the messed up font - it's current revision) if I have an active (non-disabled) label that utilizes the messed up font it works fine - both that label and the dynamically loaded one display correctly.  I can reproduce this right now by deleting the label that uses the font in question (or changing it to another font) so that there are no enabled labels using this font in the scene, closing Unity, opening Unity back up and clicking run.  The prefab with the font in question gets loaded and displays as a garbled mess.

I am happy to answer questions and try things out - and even give ArenMook access to the project, if there is interest in tracking it down.

P.S.  I already tried re-assigning the font in the prefab.

yuriks

  • Guest
Re: Font scramble on save bug?
« Reply #3 on: October 18, 2013, 12:41:53 PM »
I'm also having the same problem, see the thread I posted yesterday: http://www.tasharen.com/forum/index.php?topic=6255.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font scramble on save bug?
« Reply #4 on: October 22, 2013, 07:43:29 PM »
I need steps to reproduce it in a clean project with NGUI in it. I obviously can't do anything about you getting it in your own project. Even if you were to give it to me in its entirety, it's generally much more difficult to accurately figure something out with a greater amount of stuff going on.

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Font scramble on save bug?
« Reply #5 on: October 22, 2013, 11:03:26 PM »
I understand your desire to have this in a clean and small test case - but I am honestly unsure I could produce such a project from scratch as I have no idea what "I did" to create it in the first place.  All I have is an SVN version of the scene that has the problem in it.

rayark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Font scramble on save bug?
« Reply #6 on: February 05, 2014, 11:44:30 PM »
Hi,

I have found a procedure to reproduce this bug.

  • First create a prefab which contains a UILabel with some text.
    The UILabel uses a bitmap font which atlas also contains other sprites.
  • Create a GameObject under UIPanel, and attach the following component "Testbed" to it.
  • Make _prefab field reference to the prefab you just created. (The one contains UILabel)
  • Save the scene. Close and restart Unity. By default, Unity will load the scene opened before exit Unity.
  • Hit play button.

  1. public class Testbed : MonoBehaviour {
  2.  
  3.         [SerializeField]
  4.         GameObject _prefab;
  5.  
  6.         void Awake(){
  7.                 GameObject go = (GameObject)GameObject.Instantiate(_prefab);
  8.  
  9.                 go.transform.parent = this.transform;
  10.                 go.transform.localPosition = Vector3.zero;
  11.                 go.transform.localScale = Vector3.one;
  12.         }
  13. }
  14.  

Testbed will instantiate the prefab with UILabel, so you will see the text of UILabel.
However, the display text will be garbled.
This is because of miscalculation of mUVRect of UIFont.

By design, mUVRect is computed in the first call of get method of UIFont.uvRect property.
  1.         public Rect uvRect
  2.         {
  3.                 get
  4.                 {
  5.                         if (mReplacement != null) return mReplacement.uvRect;
  6.  
  7.                         if (mAtlas != null && (mSprite == null && sprite != null))
  8.                         {
  9.                                 //compute mUVRect
  10.                         }
  11.                         return mUVRect;
  12.                 }
  13.  

However, if mSprite is assigned and not equal to null due to some reason,
the codition
  1. mAtlas != null && (mSprite == null && sprite != null)
  2.  
will always be false, and mUVRect will be never computed.
I have used debugger to monitor UIFont.mSprite and found that
mSprite will automatically assigned to an empty UISpriteData created by the default constructor when entering play mode.

But I cannot find where UIFont.mSprite is assigned, so I guess UIFont.mSprite is assigned an empty object created by Unity debug serialization in very first stage of launching Play Mode.
To fix the problem, change the condition
  1. mAtlas != null && (mSprite == null && sprite != null)
  2.  
in UISprite.uvRect.get to
  1. mAtlas != null && ( !mSpriteSet && sprite != null)
  2.  
.



Alvin





« Last Edit: February 06, 2014, 12:23:56 AM by rayark »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font scramble on save bug?
« Reply #7 on: February 06, 2014, 10:34:42 PM »
I followed your steps to the letter, but everything worked as expected on my end, at least in the latest version.

1. New scene, ALT+SHIFT+L, using Arimo20, saved as a prefab.
2. ALT+SHIFT+N, attached a new script. Except in mine I used NGUITools.AddChild instead. It sets the parent, position, scale, and game object layer so you don't need to do it manually.
3. Referenced the prefab from step 1.
4. Saved the scene, restarted Unity, hit Play. Text showed up just fine.

Still, I see no harm in keeping that line you changed.