Hey all,
I'm getting an unpredictable and untraceable exception when I attempt to resize my game panel in WinForms. Sometimes it happens after a few seconds of resizing, sometimes it takes as much as half a minute. It seems to be caused by a high frequency of calling GraphicsDevice.Reset.
Here's my code:
| private void HandleViewportResize(object sender, EventArgs e) |
| { |
| if (panel.Width == 0 || panel.Height == 0) |
| return; |
| |
| redrawTimer.Stop(); |
| |
| PresentationParameters pp = device.PresentationParameters.Clone(); |
| pp.BackBufferHeight = panel.Height; |
| pp.BackBufferWidth = panel.Width; |
| |
| device.Reset(pp); |
| |
| redrawTimer.Start(); |
| } |
Unpredictably [as I slowly resize the panel], the device.Reset(pp) line will throw the following exception:
| ************** Exception Text ************** |
| System.InvalidOperationException: An unexpected error has occurred. |
| at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Reset(PresentationParameters presentationParameters, GraphicsAdapter graphicsAdapter) |
| at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Reset(PresentationParameters presentationParameters) |
This exception tells me nothing and it isn't documented on the MSDN site,
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.graphicsdevice.reset.aspx
I put it in a try-catch block, but once the error occurs, something is permanently broken and it catches there repeatedly until something else crashes within a second.
Has anyone else seen this sort of behavior before? Any ideas on how to fix it?
Thanks in advance.
Luke