Hi,
I am having issues with textures getting lost on app resume in MonoGame 3.2.
I have narrowed this down to a really simple ‘game’ - source file attached. What seems to happen is that if I render two different textures on draw all textures are lost, if I only draw one (or the same texture multiple times) all is fine and the reload occurs correctly.
Am I doing something wrong here or is this a bug? All works fine pre pause/resume and I have apps with pretty complex stuff going on.
I never used to have an issue with this so I don’t know if this has been caused by an update to Xamarin or what. I have managed to implement a hacky fix for this by editing the MG source to allow a ContentManager.Unload( string path ) method which enables me to unload textures and reload them when the app resumes but this is obviously a nasty hack!
Any input appreciated.
cheers
#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion
namespace MonoGame_Android_Test
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private Texture2D sometexture;
private Texture2D anothertexture;
public Game1 ()
{
graphics = new GraphicsDeviceManager (this);
graphics.SupportedOrientations = DisplayOrientation.Portrait;
Content.RootDirectory = "Content";
graphics.IsFullScreen = true;
System.Diagnostics.Debug.Write ("Constructing!");
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize ()
{
// TODO: Add your initialization logic here
base.Initialize ();
System.Diagnostics.Debug.Write ("Initializing!");
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent ()
{
//TODO: use this.Content to load your game content here
sometexture = Content.Load<Texture2D>("ninja");
anothertexture = Content.Load<Texture2D>("minininja");
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update (GameTime gameTime)
{
// TODO: Add your update logic here
base.Update (gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw (GameTime gameTime)
{
graphics.GraphicsDevice.Clear (Color.CornflowerBlue);
SpriteBatch spriteBatch;
spriteBatch = new SpriteBatch (GraphicsDevice);
spriteBatch.Begin();
spriteBatch.Draw (sometexture, new Vector2(128,128), Color.White);
spriteBatch.Draw (anothertexture, Vector2.Zero, Color.White);
spriteBatch.End ();
base.Draw (gameTime);
}
}
}