Hi,
I’ve been porting a game from Android to Windows Phone and now I’m running into the same issue we had over there - namely whenever you background the app and resume it, textures are lost - this is now happening on Windows Phone! I know this has been fixed for Android but it seems we now need the same fix for WP.
Some basic code that I’m using:
//decl
private Texture2D pixelTexture;
//in LoadContent()
pixelTexture = new Texture2D(GraphicsDevice, 1, 1, true, SurfaceFormat.Color);
pixelTexture.SetData(new[] { Color.White });
//in Draw()
Rectangle rectHealth = new Rectangle(30, 30, 100, 30);
_spriteBatch.Draw(pixelTexture, rectHealth, Color.Green * 0.9f);
Now all the above works perfectly - a rectangle is drawn to the screen. However, whenever you background the app - hit the Windows button or switch between an app and then resume the game, it never seems to draw pixelTexture again - nothing is drawn.
Furthermore, after the resume, if I try and do a pixelTexture.GetData() call, I get the following error:
{System.NullReferenceException: Object reference not set to an instance of an object.
at SharpDX.Direct3D11.Device.CreateTexture2D(Texture2DDescription& descRef, DataBox[] initialDataRef, Texture2D texture2DOut)
at SharpDX.Direct3D11.Texture2D…ctor(Device device, Texture2DDescription description)
at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T](Int32 level, Nullable1 rect, T[] data, Int32 startIndex, Int32 elementCount) at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T](T[] data) at Roids.App.Application_Deactivated(Object sender, DeactivatedEventArgs e) at System.EventHandler
1.Invoke(Object sender, TEventArgs e)
at Microsoft.Phone.Shell.PhoneApplicationService.FireDeactivated(UInt32 reason)
at Microsoft.Phone.TaskModel.Interop.ITask.Pause.Invoke(UInt32 reason)
at Microsoft.Phone.TaskModel.Interop.Task.FireOnPause(UInt32 reason)}
Anyone have any ideas?
Many thanks,
Ian.