I keep getting NullReferenceException when I create a spirte. It only happens when I close the application, but strangely not the first time I run the application, only after that. I must not be disposing of the texture properly. Can anyone help Here is some of my code:
private void OnDeviceLost(object sender, EventArgs e)
{
if (Tile.sprite != null)
{
Tile.sprite.Dispose();
Tile.sprite = null;
}
}
I also tried similiar code in the OnDestroyDevice method and still get the exception. Thank you for any suggestions.

NullReferenceException
Johan Levin
Joeouts
You should also consider adding another condition to the if, making sure that Tile itself is not null. Therefore, instead of
if (Tile.sprite != null)
you should have
if (Tile != null && Tile.sprite != null)
Roger Willcocks
Scott Coffey
hy. it might have an answer for you ...or not. maybe you should give up this line
Tile.sprite = null ; // .sprite is already disposed.