I'm playing with XNA 4.0, VS2010. I've created a window (not maximized) and drawn some sprites. All is good until I resize the window, after which the sprites stop displaying or only partially display. I'm pretty sure it has something to do with needing to reset the device or something, but can't find any clear instructions or sample code. It's not just a case of needing to increase the preferredbackbuffer size, because even if I shrink the window I get this symptom. I've looked at the source code that I was able to get from Microsoft before they shut down XNA, but it doesn't actually explain anything.

Any help or advice?

If it makes any difference I'm creating DrawableGameComponents and doing my updates and drawing in their Draw/Update routines.

  • \$\begingroup\$ So, while reading random topics I came upon a comment to the effect that a device reset clears rendertargets. Eek! Does it clear textures as well? Does this essentially mean that I have to rebuild all my sprites from the original PNGs every time the window is resized? \$\endgroup\$
    – Donutz
    May 2, 2013 at 16:33
  • \$\begingroup\$ If you're into XNA, I suggest you try MonoGame. It's open-source, and pretty decent. \$\endgroup\$
    – ashes999
    Jul 2, 2013 at 22:43

2 Answers 2


When you change the size of the xna control... the viewport is changed...

so you have to recreate your camera projection matrix..

if you are using spritebatch you should recreate it to initialize the projection matrix that it uses internally.


So, after some research, I found the problem (Jamie Hyneman: Well, THERE'S your problem!). Essentially the comment I referenced earlier describes the issue. When you change window size, the device is lost. When the device is lost, rendertargets are invalidated (but not textures). You can either check the RenderTarget2D.IsContentLost flag, or attach to the RenderTarget2D.ContentLost event to trap this as it happens.

Also, the Rendertargets don't seem to ALWAYS get invalidated. It may depend on resource usage.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .