Windows Phone 7 XNA game quits on load, no error messages
I'm trying to get a Windows Phone 7 XNA game to run in the emulator, however it simply quits after calling the Game.Initialize function. The only output it gives is:
A first chance exception of type 'System.NotSupportedException' occurred in Microsoft.Xna.Framework.Graphics.dll 'taskhost.exe' (Managed): Loaded 'Microsoft.Xna.Framework.GamerServices.dll' A first chance exception of type 'System.Threading.ThreadAbortException' occurred in Microsoft.Xna.Framework.dll
No idea why, the same program runs fine when running for Windows desktop.
OK upon further investigation I've found that the error occurs because I'm initailizing spritebatch in Game.Initialize:
base.Initialize();
if (spriteBatch == null)
{
spriteBatch开发者_高级运维 = new SpriteBatch(GraphicsDevice);
}
If I remove spriteBach = new ... it runs fine, however when I initialize it the update/draw functions the game WILL just exit...
You cannot use the GraphicsDevice
(like, for example, by having SpriteBatch
create the various graphics device resources it requires) until LoadContent
is called, as the graphics device is not ready until then.
See Game.GraphicsDevice
on MSDN:
Do not access this property until LoadContent is called.
OK I found out what the problem was. I was basically trying to draw a non power of 2 texture while using texture wrapping which the reach API of Windows Phone 7 does not like. I'm not sure why I didn't get an exception thrown for this (last time I did something like this I actually got an exception thrown).
I should have been more clear in my question, when I didn't initialize spritebatch I was also skeeping draw calls too.
At any rate that was the problem.
精彩评论