From 2837adaf9d454d356e16ddbd9c62692894a2a131 Mon Sep 17 00:00:00 2001 From: BigRedPK Date: Wed, 12 Jun 2013 10:46:05 -0500 Subject: [PATCH 1/2] Update Util.cs RenderTarget2D is volatile. This means when there is any change to screen resolution, the content will be lost. This is common when changing to full-screen, alt+tab, screensavers, and locking/unlocking the computer. We can counteract this by directly setting the content of Texture2D. --- spine-xna/src/Util.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spine-xna/src/Util.cs b/spine-xna/src/Util.cs index 1c9135c84..c6c969567 100644 --- a/spine-xna/src/Util.cs +++ b/spine-xna/src/Util.cs @@ -76,7 +76,19 @@ namespace Spine { // Release the GPU back to drawing to the screen device.SetRenderTarget(null); - return result as Texture2D; + // RenderTarget2D are volatile and will be lost on screen resolution changes. + // So instead of using this directly, we create a non-voliate Texture2D. + // This is computationally slower, but should be safe as long as it is done + // on load. + Texture2D resultTexture = new Texture2D(device, (int)file.Width, (int)file.Height); + Color[] resultContent = new Color[Convert.ToInt32(file.Width * file.Height)]; + result.GetData(resultContent); + resultTexture.SetData(resultContent); + + // Dispose of the RenderTarget2D immediately. + result.Dispose(); + + return resultTexture; } } } From 877fc97d219f40eb0f412a6529e15ce0fd277873 Mon Sep 17 00:00:00 2001 From: BigRedPK Date: Wed, 12 Jun 2013 10:46:37 -0500 Subject: [PATCH 2/2] Update Util.cs Remove unneeded casts. --- spine-xna/src/Util.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-xna/src/Util.cs b/spine-xna/src/Util.cs index c6c969567..6db93e95d 100644 --- a/spine-xna/src/Util.cs +++ b/spine-xna/src/Util.cs @@ -80,7 +80,7 @@ namespace Spine { // So instead of using this directly, we create a non-voliate Texture2D. // This is computationally slower, but should be safe as long as it is done // on load. - Texture2D resultTexture = new Texture2D(device, (int)file.Width, (int)file.Height); + Texture2D resultTexture = new Texture2D(device, file.Width, file.Height); Color[] resultContent = new Color[Convert.ToInt32(file.Width * file.Height)]; result.GetData(resultContent); resultTexture.SetData(resultContent);