From 6af79d64a2d8ab37403e7f334e4aaa2e671bb1d7 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 4 Dec 2018 22:16:50 +0200 Subject: [PATCH] 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 --- .../BarotraumaClient/Source/DebugConsole.cs | 10 +++++++++- Barotrauma/BarotraumaClient/Source/Program.cs | 17 ++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs index c3a9f5230..102adfbbd 100644 --- a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs @@ -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); } diff --git a/Barotrauma/BarotraumaClient/Source/Program.cs b/Barotrauma/BarotraumaClient/Source/Program.cs index 2e3f81929..966d4bb06 100644 --- a/Barotrauma/BarotraumaClient/Source/Program.cs +++ b/Barotrauma/BarotraumaClient/Source/Program.cs @@ -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); }