Author Topic: Font Maker corrupts atlas  (Read 7563 times)

ivarhill

  • Guest
Font Maker corrupts atlas
« on: January 27, 2013, 03:32:08 PM »
I've been using NGUI for my project for a while now, and it's working really well - except for one very annoying issue which I hope is just something on my end and can be fixed somehow.

Basically, whenever I create or replace a font using the NGUI Font Maker, there's a chance that Unity will crash - and once I have started it again, the atlas that font was in will be corrupted - all the textures are still there but the references for them seems to be messed up - an example here:


If I use the Atlas Maker to reimport the textures affected, this solves the issue - however, this affects fonts as well and the only way to fix these is to replace them using the Font Maker - which has a chance of causing the same problem again. Furthermore, sometimes the atlas seems to get messed up even without Unity crashing - always when doing something related to fonts, however.

This turns creating fonts into a russian roulette where every time I create/replace a font there's a chance I'll have to replace all my fonts again. I'm thinking I might be doing something wrong when creating the fonts. Here is one of my font folders with some of my fonts - .txt file, images, and prefabs:
https://dl.dropbox.com/u/7821237/fonts.zip

I'm using the same .txt for all of these since the only thing different between them is the color. I'm using Unity 4 on Windows 8 - some help in this matter would be greatly appreciated, since I'm really stumbling in the dark here.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Font Maker corrupts atlas
« Reply #1 on: January 27, 2013, 03:33:53 PM »
Windows 8 Unity issue perhaps? I've never encountered this before.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Font Maker corrupts atlas
« Reply #2 on: January 28, 2013, 06:41:17 AM »
Hmm, this is indeed a weird issue. I've been using Unity and NGUI on windows 8 as well, and haven't seen this.

Where do you keep your project files? Maybe windows locks some of the files, if for instance it's inside program files. Or maybe you have an over-eager antivirus that locks the file while scanning, which causes unity to spass out.

ivarhill

  • Guest
Re: Font Maker corrupts atlas
« Reply #3 on: January 29, 2013, 09:52:50 AM »
I'm using a Dropbox pro account for backups and version control, which is where I have my game files - to prevent files from getting locked due to syncing, however, I always turn syncing off when having Unity open.

Could using the same .txt file for all fonts have anything to do with it? Doesn't seem likely, but you never know...

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: Font Maker corrupts atlas
« Reply #4 on: January 29, 2013, 01:54:07 PM »
I have this same exact issue, except I am using vista.  Usually, going to the font prefab thing and dragging over the txt file to the proper field will pop it back into place.  But my most recent font screwed up another one and made the old font think its location is the new font.  Not a big deal for me, as the old font is no longer used.  I don't know how to reliable reproduce this problem either... It just happens sometimes.

Rozik

  • Guest
Re: Font Maker corrupts atlas
« Reply #5 on: May 01, 2013, 04:49:07 AM »
Has anyone solved this?

I have the same Problem on MAC.

I use 3 Atlases SD HD and UHD and its a real pain when they all get corrupted when adding a new Font.

Unity crashing doesnt bother me but having to recreate all atlases over and over is a problem.

Thx in advance if anyone has any ideas for a workaround.

ivarhill

  • Guest
Re: Font Maker corrupts atlas
« Reply #6 on: May 01, 2013, 04:53:21 AM »
I still have this issue, I've postponed development of this part of the game until it can be fixed, sadly - it's very frustrating, especially as the rest of NGUI works so well.

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Font Maker corrupts atlas
« Reply #7 on: May 01, 2013, 06:13:42 AM »
We get this issue in Windows7 when changing fonts too in NGUI, but only with large atlases.
I believe the problem is Unity related and not a fault of NGUI. When you have a lot of assets moving around or just a lot in the scene in general, behaviour in Unity can be erratic. The same issue happens here when someone commits a lot of resources at once. When you do that Unity needs to re-import them, and doing so it will often crash half way through and screw up other stuff, unless you reboot Unity, sometimes it crashes 2 or 3 times and gfx get corrupted before it finally finishes.

My crappy advice would be to restart your computer and then make your font changes on a fresh boot, chances are you're likely to have lots of memory remaining not chomped away by constant usage Unity and it probably won't crash.
Or edit your fonts in a completely empty scene.

I wonder if Unity 4 is any different. We are still using the final build of Unity3.

apocriva

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Font Maker corrupts atlas
« Reply #8 on: May 01, 2013, 06:18:58 AM »
We use a half dozen+ font faces in the games we're working on right now, and we see this issue pretty routinely. I'm not sure what the cause is, but the result is that the .prefab for the fonts sometimes do not get updated when modifying an atlas -- mostly (always?) when adding/updating a font.

Fortunately the solution for corrupted fonts is pretty straightforward. Simply select the font prefab and drag in the source .fnt file (generated by BMFont or whatnot) into the "Import Data" field in the inspector.



The issue you mention with a totally corrupted atlas... I have seen that before, due to the same thing (crash while importing font). I believe I panicked and reverted my entire workspace though. :) hehe

Large atlases and Unity instability may be to blame, as ENAY mentions. We're using Unity 4, though.

Foj

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Font Maker corrupts atlas
« Reply #9 on: August 13, 2013, 10:20:25 AM »
Hopefully some is still watching this thread,


Is this the issue you are all getting?
 
After updating the Atlas the font is corrupted. The atlas prefab looks fine in the Inspector (image_01).

 But the font prefab shows the green boarder in the wrong place (image_02). (And I think I can see the corrupted font outline is using graphics from this region.)
 
I can’t find a quick fix. Just tried the one from apocriva. That wasn’t instant but may have helped my: delete from Atlas; reapply with NGUI font maker; shut down Unity – random-cycle till it works, solution.
 
Once working the green-boarder will appear in right place on the font prefab too.

Erhune

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Font Maker corrupts atlas
« Reply #10 on: August 28, 2013, 06:04:56 AM »
I have the same problem here (Unity 4.2.0f4 Pro on Windows 7 Pro 64 bit with NGUI 2.6.4): every time I update my atlas, a few of the font prefabs that use sprites in this atlas get messed up. Just reassigning the same sprite in the Font inspector fixes the problem, but it's quite time-consuming to go over each font manually after every atlas update, so I've made 2 simple scripts:
- a Panel in my game that shows a sample of all the fonts I have in my project
- a small Editor script to loop over all the font prefabs and reassign the sprite, like this:

  1.  [MenuItem("LBM/Fix fonts")]
  2.     public static void FixFonts()
  3.     {
  4.         var fonts = Resources.FindObjectsOfTypeAll(typeof (UIFont)) as UIFont[];
  5.         Debug.Log(string.Format("Found {0} font(s):", fonts.Length));
  6.         foreach (var font in fonts)
  7.         {
  8.             var sprite = font.spriteName;
  9.             Debug.Log(string.Format("{0} with sprite {1}", font.name, sprite));
  10.             font.spriteName = "";
  11.             font.spriteName = sprite;
  12.             EditorUtility.SetDirty(font.gameObject);
  13.         }
  14.         Debug.Log("Don't forget to save the scene to commit all the changes!");
  15.     }

Note that the Editor script actually loops over all the fonts, but only the fonts that are *actually* used in the Scene view while the game is running are fixed (thus the test Panel that shows all my font, so I can fix them all at once)

Hope that helps some people who have the same issue, and of course I'm crossing fingers for a "real" fix of this bug, and not a workaround.

jbgh2

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Font Maker corrupts atlas
« Reply #11 on: February 26, 2014, 06:33:06 PM »
I'm seeing the same problem, it occurs when the Font Maker rearranges the underlying atlas but doesn't change the other font prefabs that reference that atlas.

This messes all the UVs in the prefab and leads to the effects.

You can fix it by manually editing the prefab in a text editor or force Font Maker to regenerate the prefab of the other Fonts.