private static bool CheckException(GameMain game, Exception e) { #if WINDOWS if (e is SharpDX.SharpDXException) { DebugConsole.NewMessage("SharpDX exception caught. (" + e.Message + "). Attempting to fix...", Microsoft.Xna.Framework.Color.Red); switch ((uint)((SharpDX.SharpDXException)e).ResultCode.Code) { case 0x887A0022: //DXGI_ERROR_NOT_CURRENTLY_AVAILABLE switch (restartAttempts) { case 0: //just wait and try again DebugConsole.NewMessage("Retrying after 100 ms...", Microsoft.Xna.Framework.Color.Red); System.Threading.Thread.Sleep(100); return(true); case 1: //force focus to this window DebugConsole.NewMessage("Forcing focus to the window and retrying...", Microsoft.Xna.Framework.Color.Red); var myForm = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(game.Window.Handle); myForm.Focus(); return(true); case 2: //try disabling hardware mode switch if (GameMain.Config.WindowMode == WindowMode.Fullscreen) { DebugConsole.NewMessage("Failed to set fullscreen mode, switching configuration to borderless windowed", Microsoft.Xna.Framework.Color.Red); GameMain.Config.WindowMode = WindowMode.BorderlessWindowed; GameMain.Config.Save("config.xml"); } return(false); default: return(false); } case 0x80070057: //E_INVALIDARG/Invalid Arguments DebugConsole.NewMessage("Invalid graphics settings, attempting to fix...", Microsoft.Xna.Framework.Color.Red); GameMain.Config.GraphicsWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; GameMain.Config.GraphicsHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; DebugConsole.NewMessage("Display size set to " + GameMain.Config.GraphicsWidth + "x" + GameMain.Config.GraphicsHeight, Microsoft.Xna.Framework.Color.Red); game.ApplyGraphicsSettings(); return(true); default: return(false); } } #endif return(false); }