(d9829ac) v0.9.4.0

This commit is contained in:
Regalis
2019-10-24 18:05:42 +02:00
parent 9aa12bcac2
commit b39922a074
319 changed files with 12516 additions and 6815 deletions
+23 -110
View File
@@ -9,8 +9,7 @@ using Barotrauma.Steam;
using System.Diagnostics;
#if WINDOWS
using System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;
using SharpDX;
#endif
#endregion
@@ -31,135 +30,41 @@ namespace Barotrauma
[STAThread]
static void Main(string[] args)
{
SteamManager.Initialize();
GameMain game = null;
#if !DEBUG
try
{
#endif
SteamManager.Initialize();
game = new GameMain(args);
#if !DEBUG
}
catch (Exception e)
{
if (game != null) game.Dispose();
CrashDump(null, "crashreport.log", e);
return;
}
#endif
#if DEBUG
game.Run();
#else
bool attemptRestart = false;
do
{
try
{
game.Run();
attemptRestart = false;
}
catch (Exception e)
{
if (restartAttempts < 5 && CheckException(game, e))
{
attemptRestart = true;
restartAttempts++;
}
else
{
CrashDump(game, "crashreport.log", e);
attemptRestart = false;
}
}
} while (attemptRestart);
#endif
#if !DEBUG
try
{
#endif
game.Run();
game.Dispose();
#if !DEBUG
}
catch (Exception e)
{
CrashDump(null, "crashreport.log", e);
}
#endif
}
private static bool CheckException(GameMain game, Exception e)
{
#if WINDOWS
if (e is SharpDX.SharpDXException sharpDxException)
{
DebugConsole.NewMessage("SharpDX exception caught. ("
+ e.Message + ", " + sharpDxException.ResultCode.Code.ToString("X") + "). Attempting to fix...", Microsoft.Xna.Framework.Color.Red);
switch ((UInt32)sharpDxException.ResultCode.Code)
try
{
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 = (Form)Control.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.SaveNewPlayerConfig();
}
return false;
default:
DebugConsole.NewMessage("Failed to resolve the DXGI_ERROR_NOT_CURRENTLY_AVAILABLE exception. Give up and let it crash :(", Microsoft.Xna.Framework.Color.Red);
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:
DebugConsole.NewMessage("Unknown SharpDX exception code (" + sharpDxException.ResultCode.Code.ToString("X") + ")", Microsoft.Xna.Framework.Color.Red);
return false;
CrashDump(game, "crashreport.log", e);
}
catch (Exception e2)
{
CrashMessageBox("Barotrauma seems to have crashed, and failed to generate a crash report: "
+ e2.Message + "\n" + e2.StackTrace.ToString(),
null);
}
game?.Dispose();
return;
}
#endif
return false;
}
public static void CrashMessageBox(string message, string filePath)
{
#if WINDOWS
MessageBox.Show(message, "Oops! Barotrauma just crashed.", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
Microsoft.Xna.Framework.MessageBox.ShowWrapped(Microsoft.Xna.Framework.MessageBox.Flags.Error, "Oops! Barotrauma just crashed.", message);
// Open the crash log.
Process.Start(filePath);
if (!string.IsNullOrWhiteSpace(filePath)) { Process.Start(filePath); }
}
static void CrashDump(GameMain game, string filePath, Exception exception)
@@ -259,10 +164,18 @@ namespace Barotrauma
sb.AppendLine("\n");
sb.AppendLine("Exception: " + exception.Message);
#if WINDOWS
if (exception is SharpDXException sharpDxException && ((uint)sharpDxException.HResult) == 0x887A0005)
{
var dxDevice = (SharpDX.Direct3D11.Device)game.GraphicsDevice.Handle;
sb.AppendLine("Device removed reason: " + dxDevice.DeviceRemovedReason.ToString());
}
#endif
if (exception.TargetSite != null)
{
sb.AppendLine("Target site: " + exception.TargetSite.ToString());
}
sb.AppendLine("Stack trace: ");
sb.AppendLine(exception.StackTrace);
sb.AppendLine("\n");