Texture and font issues on Device ( Lumia 520 )

Topics: Windows Phone 8
Sep 25, 2013 at 5:06 AM
After 3 weeks working on porting game to WP8 used cocos2d-xna, everything looks smooth on emulator. Yesterday I built on real device to test performance but my Game draw not correct with texture and font.
First time open:
  • Menu:
I pressed Windows -> Back to resume my game
  • Main menu:
press Windows -> Back to resume again:

I decided to exit my Game and open it again:
  • Main menu:
Another issue is sometimes resuming game causes error by SharpDX ( inputLayout ).

Please help me how to handle with these issues
Sep 25, 2013 at 6:15 AM

Are you using asynchronous texture loading?

The last image looks like the render target used to render the labels is becoming corrupt or not being created properly.
Sep 25, 2013 at 7:36 AM
Dear totallyevil,
 How can i load textures synchronously? And about labels, i only use CCLabelTTF with Arial font ( i cached it in AppDelegate ).
Sep 25, 2013 at 11:15 AM
I found all these bug caused by SpriteFont loading. Sometimes CCLabelTTF instance init and show on console this exception so if game resume or change scene that use this error font will cause crashed.
A first chance exception of type 'System.NullReferenceException' occurred in MonoGame.Framework.DLL
An exception of type 'System.NullReferenceException' occurred in MonoGame.Framework.DLL and wasn't handled before a managed/native boundary
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.ApplyState(Boolean applyShaders)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawUserIndexedPrimitives[T](PrimitiveType primitiveType, T[] vertexData, Int32 vertexOffset, Int32 numVertices, Int16[] indexData, Int32 indexOffset, Int32 primitiveCount, VertexDeclaration vertexDeclaration)
   at Microsoft.Xna.Framework.Graphics.SpriteBatcher.FlushVertexArray(Int32 start, Int32 end)
   at Microsoft.Xna.Framework.Graphics.SpriteBatcher.DrawBatch(SpriteSortMode sortMode)
   at Microsoft.Xna.Framework.Graphics.SpriteBatch.End()
   at Cocos2D.CCTexture2D.InitWithString(String text, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, String fontName, Single fontSize)
Sep 25, 2013 at 5:38 PM
Are you using scaled textures, or very large textures? (hiDef or Reach profile?)

It looks as if the RenderTarget used for the TTF label is not getting initialized properly. This could be a framebuffer memory problem, where you are loading it up with a lot of large textures, and then trying to create a new RenderTarget with the TTF label, which then fails.
Sep 25, 2013 at 5:39 PM
Note the purple background showing on the screen? That tells me that the DiscardContents mode on the render target is dumping that texture, maybe to conserve memory.
Sep 25, 2013 at 5:41 PM
How can i load textures synchronously?
CCTextureCache {
      public void AddImageAsync(string fileimage, Action<CCTexture2D> action)

The "action" is called after the texture is loaded.

We've seen mixed success with loading async textures through. Sometimes they don't load successfully, and no indication as to why they don't load. That mostly happens on Android devices.
Sep 26, 2013 at 4:41 AM
I use Reach Profile ( i created a Windows Phone 7 XNA project to build content then copy to WP8's Content folder) to load about 8 atlas textures ( POT - max width and height is 1024px).

I tried to use AddImageAsync but nothing goes better.
Oct 7, 2013 at 1:00 PM
Edited Oct 7, 2013 at 1:02 PM
Dear DaiHuynh,

Did you fix this problem with font loading? If fixed, plz show this solution for me and everyone?
I met same issuse :(
Oct 8, 2013 at 7:44 AM
Hi daniel19xx,
I found a solution for this issue. You should use CCLabelBMFont instead of CCLabelTTF. You need a Cocos2dXNA.ContentPipeline dll for compiling your bitmap fonts to xnb. 
Oct 9, 2013 at 4:11 AM
Edited Oct 9, 2013 at 4:11 AM
Could you give me this DLL or mini project to compile bitmap fonts to xnb file.
I can not get or give it.
My email is daniellaw.fr@gmail.com. Thank you.