- attempt to fix "DXGI_ERROR_NOT_CURRENTLY_AVAILABLE" exceptions (the game tries forcing focus to the window and running GameMain again, and if that doesn't help, disables hardware mode switching)
- messages can be added to debugconsole before it's initialized
This commit is contained in:
@@ -321,6 +321,10 @@
|
|||||||
<Reference Include="RestSharp">
|
<Reference Include="RestSharp">
|
||||||
<HintPath>..\packages\RestSharp.105.1.0\lib\net4\RestSharp.dll</HintPath>
|
<HintPath>..\packages\RestSharp.105.1.0\lib\net4\RestSharp.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="SharpDX, Version=2.6.3.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows\SharpDX.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
|||||||
@@ -64,6 +64,15 @@ namespace Barotrauma
|
|||||||
textBox = new GUITextBox(new Rectangle(0,0,0,20), Color.Black, Color.White, Alignment.BottomLeft, Alignment.Left, GUI.Style, frame);
|
textBox = new GUITextBox(new Rectangle(0,0,0,20), Color.Black, Color.White, Alignment.BottomLeft, Alignment.Left, GUI.Style, frame);
|
||||||
textBox.Color = Color.Black * 0.7f;
|
textBox.Color = Color.Black * 0.7f;
|
||||||
|
|
||||||
|
//messages already added before initialization -> add them to the listbox
|
||||||
|
List<ColoredText> unInitializedMessages = new List<ColoredText>(Messages);
|
||||||
|
Messages.Clear();
|
||||||
|
|
||||||
|
foreach (ColoredText msg in unInitializedMessages)
|
||||||
|
{
|
||||||
|
NewMessage(msg.Text, msg.Color);
|
||||||
|
}
|
||||||
|
|
||||||
NewMessage("Press F3 to open/close the debug console", Color.Cyan);
|
NewMessage("Press F3 to open/close the debug console", Color.Cyan);
|
||||||
NewMessage("Enter \"help\" for a list of available console commands", Color.Cyan);
|
NewMessage("Enter \"help\" for a list of available console commands", Color.Cyan);
|
||||||
|
|
||||||
@@ -752,6 +761,14 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Messages.Add(new ColoredText(msg, color));
|
Messages.Add(new ColoredText(msg, color));
|
||||||
|
|
||||||
|
if (Messages.Count > MaxMessages)
|
||||||
|
{
|
||||||
|
Messages.RemoveRange(0, Messages.Count - MaxMessages);
|
||||||
|
}
|
||||||
|
|
||||||
|
//listbox not created yet, don't attempt to add
|
||||||
|
if (listBox == null) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var textBlock = new GUITextBlock(new Rectangle(0, 0, listBox.Rect.Width, 0), msg, GUI.Style, Alignment.TopLeft, Alignment.Left, null, true, GUI.SmallFont);
|
var textBlock = new GUITextBlock(new Rectangle(0, 0, listBox.Rect.Width, 0), msg, GUI.Style, Alignment.TopLeft, Alignment.Left, null, true, GUI.SmallFont);
|
||||||
@@ -765,14 +782,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Messages.Count > MaxMessages)
|
|
||||||
{
|
|
||||||
Messages.RemoveRange(0, Messages.Count - MaxMessages);
|
|
||||||
}
|
|
||||||
|
|
||||||
//messages.Add(new ColoredText(msg, color));
|
|
||||||
|
|
||||||
selectedIndex = listBox.children.Count;
|
selectedIndex = listBox.children.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
get { return NetworkMember as GameClient; }
|
get { return NetworkMember as GameClient; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameMain()
|
public GameMain()
|
||||||
{
|
{
|
||||||
Graphics = new GraphicsDeviceManager(this);
|
Graphics = new GraphicsDeviceManager(this);
|
||||||
@@ -119,21 +119,11 @@ namespace Barotrauma
|
|||||||
Config.WasGameUpdated = false;
|
Config.WasGameUpdated = false;
|
||||||
Config.Save("config.xml");
|
Config.Save("config.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
graphicsWidth = Config.GraphicsWidth;
|
|
||||||
graphicsHeight = Config.GraphicsHeight;
|
|
||||||
Graphics.SynchronizeWithVerticalRetrace = Config.VSyncEnabled;
|
|
||||||
|
|
||||||
Graphics.HardwareModeSwitch = Config.WindowMode != WindowMode.BorderlessWindowed;
|
ApplyGraphicsSettings();
|
||||||
|
|
||||||
Graphics.IsFullScreen = Config.WindowMode == WindowMode.Fullscreen || Config.WindowMode == WindowMode.BorderlessWindowed;
|
|
||||||
Graphics.PreferredBackBufferWidth = graphicsWidth;
|
|
||||||
Graphics.PreferredBackBufferHeight = graphicsHeight;
|
|
||||||
Content.RootDirectory = "Content";
|
Content.RootDirectory = "Content";
|
||||||
|
|
||||||
//graphics.SynchronizeWithVerticalRetrace = false;
|
|
||||||
//graphics.ApplyChanges();
|
|
||||||
|
|
||||||
FrameCounter = new FrameCounter();
|
FrameCounter = new FrameCounter();
|
||||||
|
|
||||||
//IsMouseVisible = true;
|
//IsMouseVisible = true;
|
||||||
@@ -150,6 +140,20 @@ namespace Barotrauma
|
|||||||
FarseerPhysics.Settings.VelocityIterations = 1;
|
FarseerPhysics.Settings.VelocityIterations = 1;
|
||||||
FarseerPhysics.Settings.PositionIterations = 1;
|
FarseerPhysics.Settings.PositionIterations = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplyGraphicsSettings()
|
||||||
|
{
|
||||||
|
graphicsWidth = Config.GraphicsWidth;
|
||||||
|
graphicsHeight = Config.GraphicsHeight;
|
||||||
|
Graphics.SynchronizeWithVerticalRetrace = Config.VSyncEnabled;
|
||||||
|
|
||||||
|
Graphics.HardwareModeSwitch = Config.WindowMode != WindowMode.BorderlessWindowed;
|
||||||
|
|
||||||
|
Graphics.IsFullScreen = Config.WindowMode == WindowMode.Fullscreen || Config.WindowMode == WindowMode.BorderlessWindowed;
|
||||||
|
Graphics.PreferredBackBufferWidth = graphicsWidth;
|
||||||
|
Graphics.PreferredBackBufferHeight = graphicsHeight;
|
||||||
|
|
||||||
Graphics.ApplyChanges();
|
Graphics.ApplyChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Text;
|
|||||||
#if WINDOWS
|
#if WINDOWS
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -20,6 +21,8 @@ namespace Barotrauma
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
|
private static int restartAttempts;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,22 +30,84 @@ namespace Barotrauma
|
|||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
using (var game = new GameMain())
|
using (var game = new GameMain())
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
#if DEBUG
|
||||||
try
|
game.Run();
|
||||||
|
#else
|
||||||
|
bool attemptRestart = false;
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
#endif
|
try
|
||||||
game.Run();
|
{
|
||||||
#if !DEBUG
|
game.Run();
|
||||||
}
|
attemptRestart = false;
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
CrashDump(game, "crashreport.txt", e);
|
{
|
||||||
}
|
if (restartAttempts < 5 && CheckException(game, e))
|
||||||
|
{
|
||||||
|
attemptRestart = true;
|
||||||
|
restartAttempts++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CrashDump(game, "crashreport.txt", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} while (attemptRestart);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool CheckException(GameMain game, Exception e)
|
||||||
|
{
|
||||||
|
if (e is SharpDX.SharpDXException)
|
||||||
|
{
|
||||||
|
switch ((uint)((SharpDX.SharpDXException)e).ResultCode.Code)
|
||||||
|
{
|
||||||
|
case 0x887A0022: //DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
|
||||||
|
switch (restartAttempts)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
//just wait and try again
|
||||||
|
System.Threading.Thread.Sleep(100);
|
||||||
|
return true;
|
||||||
|
case 1:
|
||||||
|
//force focus to this window
|
||||||
|
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;
|
||||||
|
game.ApplyGraphicsSettings();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static void CrashMessageBox(string message)
|
public static void CrashMessageBox(string message)
|
||||||
{
|
{
|
||||||
#if WINDOWS
|
#if WINDOWS
|
||||||
@@ -63,7 +128,7 @@ namespace Barotrauma
|
|||||||
sb.AppendLine("If you'd like to help fix the bug that caused the crash, please send this file to the developers on the Undertow Games forums.");
|
sb.AppendLine("If you'd like to help fix the bug that caused the crash, please send this file to the developers on the Undertow Games forums.");
|
||||||
sb.AppendLine("\n");
|
sb.AppendLine("\n");
|
||||||
sb.AppendLine("Game version " + GameMain.Version);
|
sb.AppendLine("Game version " + GameMain.Version);
|
||||||
sb.AppendLine("Graphics mode: " + GameMain.Config.WindowMode + "x" + GameMain.Config.GraphicsHeight + " (" + GameMain.Config.WindowMode.ToString() + ")");
|
sb.AppendLine("Graphics mode: " + GameMain.Config.GraphicsWidth + "x" + GameMain.Config.GraphicsHeight + " (" + GameMain.Config.WindowMode.ToString() + ")");
|
||||||
sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name);
|
sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name);
|
||||||
sb.AppendLine("Level seed: " + ((Level.Loaded == null) ? "no level loaded" : Level.Loaded.Seed));
|
sb.AppendLine("Level seed: " + ((Level.Loaded == null) ? "no level loaded" : Level.Loaded.Seed));
|
||||||
sb.AppendLine("Loaded submarine: " + ((Submarine.MainSub == null) ? "None" : Submarine.MainSub.Name + " (" + Submarine.MainSub.MD5Hash + ")"));
|
sb.AppendLine("Loaded submarine: " + ((Submarine.MainSub == null) ? "None" : Submarine.MainSub.Name + " (" + Submarine.MainSub.MD5Hash + ")"));
|
||||||
|
|||||||
Reference in New Issue
Block a user