Hello Guest

Author Topic: Error in tk2dTextGeomGen when unsupported glyph is found from string  (Read 3936 times)

tomitukiainen

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Hello,

we have released a game that displays Facebook name of the player and her friends in ranking lists. We support most important character sets in our tk2d bitmap font but we have already a few players whose name we can't render. Most of the time unsupported glyphs are rendered empty (as we saw in testing phase) but name of one of our players causes the following exception to happen:

I/Unity   (19151): NullReferenceException: Object reference not set to an instance of an object
I/Unity   (19151):   at tk2dTextGeomGen.GetMeshDimensionsForString (System.String str, .GeomData geomData) [0x00000] in <filename unknown>:0
I/Unity   (19151):   at tk2dTextGeomGen.SetTextMeshGeom (UnityEngine.Vector3[] pos, UnityEngine.Vector2[] uv, UnityEngine.Vector2[] uv2, UnityEngine.Color32[] color, Int32 offset, .GeomData geomData) [0x00000] in <filename unknown>:0
I/Unity   (19151):   at tk2dTextMesh.DoNotUse__CommitInternal () [0x00000] in <filename unknown>:0
I/Unity   (19151):   at tk2dUpdateManager.FlushQueuesInternal () [0x00000] in <filename unknown>:0
I/Unity   (19151):   at tk2dUpdateManager.FlushQueues () [0x00000] in <filename unknown>:0
I/Unity   (19151):   at tk2dCamera.OnPreCull () [0x00000] in <filename unknown>:0

We have planned to implement a workaround: we want to render the text with a system font when it contains glyphs that we don't have in our bitmap font. Can you tell us how we could identify this situation? Pseudo code:

--
Code: [Select]
public tk2dTextMesh tk2dText;

void SetName(string playerName) {
 if(tk2dText.HasUnsupportedGlyphs(playerName)) {
   // render name with system font
   ...
 } else {
   // all glyphs supported -> render name with tk2dTextMesh
  tk2dText.text = playerName;
  tk2dText.Commit();
 }
}
« Last Edit: January 02, 2014, 03:00:24 pm by tomitukiainen »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Error in tk2dTextGeomGen when unsupported glyph is found from string
« Reply #1 on: January 02, 2014, 05:42:30 pm »
You could try adding something like this to tk2dTextMesh. This should return true if any of the characters aren't found in the array / dict. This doesn't consider formatting (^ syntax), but should work otherwise...

Code: [Select]
bool HasUnsupportedGlyphs(string source) {
InitInstance();
for (int i = 0; i < source.Length; ++i) {
char idx = _source[i];
if (_fontInst.useDictionary)
{
if (!_fontInst.charDict.ContainsKey(idx)) return true;
}
else
{
if (idx >= _fontInst.chars.Length) return true;
}
}
return false;
}


tomitukiainen

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Error in tk2dTextGeomGen when unsupported glyph is found from string
« Reply #2 on: January 03, 2014, 09:44:30 am »
Thanks! Problem solved :)