Fixed console messages that have been created before initializing the console not being present in crash logs, fixed first console message not being included in crash logs, more logging to diagnose SharpDX exceptions

This commit is contained in:
Joonas Rikkonen
2018-12-04 22:16:50 +02:00
parent 1c1fe3a161
commit 6af79d64a2
2 changed files with 19 additions and 8 deletions

View File

@@ -163,7 +163,15 @@ namespace Barotrauma
while (queuedMessages.Count > 0)
{
var newMsg = queuedMessages.Dequeue();
AddMessage(newMsg);
if (listBox == null)
{
//don't attempt to add to the listbox if it hasn't been created yet
Messages.Add(newMsg);
}
else
{
AddMessage(newMsg);
}
if (GameSettings.SaveDebugConsoleLogs) unsavedMessages.Add(newMsg);
}

View File

@@ -38,7 +38,7 @@ namespace Barotrauma
do
{
try
{
{
game.Run();
attemptRestart = false;
}
@@ -65,11 +65,12 @@ namespace Barotrauma
{
#if WINDOWS
if (e is SharpDX.SharpDXException)
if (e is SharpDX.SharpDXException sharpDxException)
{
DebugConsole.NewMessage("SharpDX exception caught. (" + e.Message + "). Attempting to fix...", Microsoft.Xna.Framework.Color.Red);
DebugConsole.NewMessage("SharpDX exception caught. ("
+ e.Message + ", " + sharpDxException.ResultCode.Code.ToString("X") + "). Attempting to fix...", Microsoft.Xna.Framework.Color.Red);
switch ((uint)((SharpDX.SharpDXException)e).ResultCode.Code)
switch ((UInt32)sharpDxException.ResultCode.Code)
{
case 0x887A0022: //DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
switch (restartAttempts)
@@ -82,19 +83,20 @@ namespace Barotrauma
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);
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);
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:
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;
}
@@ -110,6 +112,7 @@ namespace Barotrauma
return true;
default:
DebugConsole.NewMessage("Unknown SharpDX exception code (" + sharpDxException.ResultCode.Code.ToString("X") + ")", Microsoft.Xna.Framework.Color.Red);
return false;
}
}
@@ -188,7 +191,7 @@ namespace Barotrauma
sb.AppendLine("\n");
sb.AppendLine("Last debug messages:");
for (int i = DebugConsole.Messages.Count - 1; i > 0; i--)
for (int i = DebugConsole.Messages.Count - 1; i >= 0; i--)
{
sb.AppendLine("[" + DebugConsole.Messages[i].Time + "] " + DebugConsole.Messages[i].Text);
}