Pārlūkot izejas kodu

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.
BigRedPK 12 gadi atpakaļ
vecāks
revīzija
2837adaf9d
1 mainītis faili ar 13 papildinājumiem un 1 dzēšanām
  1. 13 1
      spine-xna/src/Util.cs

+ 13 - 1
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;
 		}
 	}
 }