Parcourir la source

Log window properly parses and displays managed exceptions

BearishSun il y a 10 ans
Parent
commit
2d83c7c4c0

+ 1 - 0
BansheeMono/Include/BsMonoUtil.h

@@ -154,6 +154,7 @@ namespace BansheeEngine
 				::MonoMethod* exceptionStackGetter = mono_property_get_get_method(exceptionStackProp);
 				::MonoMethod* exceptionStackGetter = mono_property_get_get_method(exceptionStackProp);
 				MonoString* exceptionStackTrace = (MonoString*)mono_runtime_invoke(exceptionStackGetter, exception, nullptr, nullptr);
 				MonoString* exceptionStackTrace = (MonoString*)mono_runtime_invoke(exceptionStackGetter, exception, nullptr, nullptr);
 
 
+				// Note: If you modify this format make sure to also modify Debug.ParseExceptionMessage in managed code.
 				String msg =  "Managed exception: " + toString(monoToWString(exceptionMsg)) + "\n" + toString(monoToWString(exceptionStackTrace));
 				String msg =  "Managed exception: " + toString(monoToWString(exceptionMsg)) + "\n" + toString(monoToWString(exceptionStackTrace));
 
 
 				LOGERR(msg);
 				LOGERR(msg);

+ 9 - 9
MBansheeEditor/EditorApplication.cs

@@ -106,13 +106,13 @@ namespace BansheeEditor
                     Selection.SceneObject = null;
                     Selection.SceneObject = null;
                 else
                 else
                 {
                 {
-                    if (EditorSettings.GetBool(ConsoleWindow.CLEAR_ON_PLAY_KEY, true))
+                    if (EditorSettings.GetBool(LogWindow.CLEAR_ON_PLAY_KEY, true))
                     {
                     {
                         Debug.Clear();
                         Debug.Clear();
 
 
-                        ConsoleWindow console = EditorWindow.GetWindow<ConsoleWindow>();
-                        if (console != null)
-                            console.Refresh();
+                        LogWindow log = EditorWindow.GetWindow<LogWindow>();
+                        if (log != null)
+                            log.Refresh();
                     }
                     }
                 }
                 }
 
 
@@ -694,13 +694,13 @@ namespace BansheeEditor
         {
         {
             if (IsStopped)
             if (IsStopped)
             {
             {
-                if (EditorSettings.GetBool(ConsoleWindow.CLEAR_ON_PLAY_KEY, true))
+                if (EditorSettings.GetBool(LogWindow.CLEAR_ON_PLAY_KEY, true))
                 {
                 {
                     Debug.Clear();
                     Debug.Clear();
 
 
-                    ConsoleWindow console = EditorWindow.GetWindow<ConsoleWindow>();
-                    if (console != null)
-                        console.Refresh();
+                    LogWindow log = EditorWindow.GetWindow<LogWindow>();
+                    if (log != null)
+                        log.Refresh();
                 }
                 }
             }
             }
 
 
@@ -787,7 +787,7 @@ namespace BansheeEditor
         /// </summary>
         /// </summary>
         private static void Internal_OnStatusBarClicked()
         private static void Internal_OnStatusBarClicked()
         {
         {
-            EditorWindow.OpenWindow<ConsoleWindow>();
+            EditorWindow.OpenWindow<LogWindow>();
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]

+ 10 - 5
MBansheeEditor/ConsoleWindow.cs → MBansheeEditor/LogWindow.cs

@@ -9,7 +9,7 @@ namespace BansheeEditor
     /// Displays a list of log messages.
     /// Displays a list of log messages.
     /// </summary>
     /// </summary>
     [DefaultSize(600, 300)]
     [DefaultSize(600, 300)]
-    public class ConsoleWindow : EditorWindow
+    public class LogWindow : EditorWindow
     {
     {
         #region Constants
         #region Constants
         public const string CLEAR_ON_PLAY_KEY = "EditorClearLogOnPlay";
         public const string CLEAR_ON_PLAY_KEY = "EditorClearLogOnPlay";
@@ -63,7 +63,7 @@ namespace BansheeEditor
         [MenuItem("Windows/Log", ButtonModifier.CtrlAlt, ButtonCode.L, 6000)]
         [MenuItem("Windows/Log", ButtonModifier.CtrlAlt, ButtonCode.L, 6000)]
         private static void OpenConsoleWindow()
         private static void OpenConsoleWindow()
         {
         {
-            OpenWindow<ConsoleWindow>();
+            OpenWindow<LogWindow>();
         }
         }
 
 
         /// <inheritdoc/>
         /// <inheritdoc/>
@@ -187,8 +187,11 @@ namespace BansheeEditor
         /// <param name="message">Message string.</param>
         /// <param name="message">Message string.</param>
         private void OnEntryAdded(DebugMessageType type, string message)
         private void OnEntryAdded(DebugMessageType type, string message)
         {
         {
-            // Check if compiler message, otherwise parse it normally
+            // Check if compiler message or reported exception, otherwise parse it as a normal log message
             ParsedLogEntry logEntry = ScriptCodeManager.ParseCompilerMessage(message);
             ParsedLogEntry logEntry = ScriptCodeManager.ParseCompilerMessage(message);
+            if (logEntry == null)
+                logEntry = Debug.ParseExceptionMessage(message);
+
             if (logEntry == null)
             if (logEntry == null)
                 logEntry = Debug.ParseLogMessage(message);
                 logEntry = Debug.ParseLogMessage(message);
 
 
@@ -327,7 +330,7 @@ namespace BansheeEditor
                 ConsoleEntryData entry = filteredEntries[sSelectedElementIdx];
                 ConsoleEntryData entry = filteredEntries[sSelectedElementIdx];
 
 
                 LocString message = new LocEdString(entry.message);
                 LocString message = new LocEdString(entry.message);
-                GUILabel messageLabel = new GUILabel(message);
+                GUILabel messageLabel = new GUILabel(message, EditorStyles.MultiLineLabel, GUIOption.FlexibleHeight());
                 mainLayout.AddElement(messageLabel);
                 mainLayout.AddElement(messageLabel);
                 mainLayout.AddSpace(10);
                 mainLayout.AddSpace(10);
 
 
@@ -353,6 +356,8 @@ namespace BansheeEditor
                         };
                         };
                     }
                     }
                 }
                 }
+
+                mainLayout.AddFlexibleSpace();
             }
             }
             else
             else
             {
             {
@@ -520,7 +525,7 @@ namespace BansheeEditor
             {
             {
                 sSelectedElementIdx = entryIdx;
                 sSelectedElementIdx = entryIdx;
 
 
-                ConsoleWindow window = GetWindow<ConsoleWindow>();
+                LogWindow window = GetWindow<LogWindow>();
                 window.RefreshDetailsPanel();
                 window.RefreshDetailsPanel();
 
 
                 RefreshEntries();
                 RefreshEntries();

+ 1 - 1
MBansheeEditor/MBansheeEditor.csproj

@@ -46,7 +46,7 @@
     <Compile Include="BuildWindow.cs" />
     <Compile Include="BuildWindow.cs" />
     <Compile Include="CodeEditor.cs" />
     <Compile Include="CodeEditor.cs" />
     <Compile Include="ColorPicker.cs" />
     <Compile Include="ColorPicker.cs" />
-    <Compile Include="ConsoleWindow.cs" />
+    <Compile Include="LogWindow.cs" />
     <Compile Include="DefaultSize.cs" />
     <Compile Include="DefaultSize.cs" />
     <Compile Include="DialogBox.cs" />
     <Compile Include="DialogBox.cs" />
     <Compile Include="DragDrop.cs" />
     <Compile Include="DragDrop.cs" />

+ 1 - 1
MBansheeEditor/ScriptCodeManager.cs

@@ -65,7 +65,7 @@ namespace BansheeEditor
                         Debug.Clear(DebugMessageType.CompilerWarning);
                         Debug.Clear(DebugMessageType.CompilerWarning);
                         Debug.Clear(DebugMessageType.CompilerError);
                         Debug.Clear(DebugMessageType.CompilerError);
 
 
-                        ConsoleWindow window = EditorWindow.GetWindow<ConsoleWindow>();
+                        LogWindow window = EditorWindow.GetWindow<LogWindow>();
                         if (window != null)
                         if (window != null)
                             window.Refresh();
                             window.Refresh();
 
 

+ 33 - 0
MBansheeEngine/Debug.cs

@@ -232,6 +232,39 @@ namespace BansheeEngine
             return newEntry;
             return newEntry;
         }
         }
 
 
+        /// <summary>
+        /// Parses a managed exception message and outputs a data object with a separate message and callstack entries.
+        /// </summary>
+        /// <param name="message">Message to parse.</param>
+        /// <returns>Parsed log message.</returns>
+        public static ParsedLogEntry ParseExceptionMessage(string message)
+        {
+            Regex headerRegex = new Regex(@"Managed exception: (.*)\n");
+            var headerMatch = headerRegex.Match(message);
+
+            if (!headerMatch.Success)
+                return null;
+
+            Regex regex = new Regex(@"  at (.*) \[.*\] in (.*):(\d*)");
+            var matches = regex.Matches(message);
+
+            ParsedLogEntry newEntry = new ParsedLogEntry();
+            newEntry.callstack = new CallStackEntry[matches.Count];
+            for (int i = 0; i < matches.Count; i++)
+            {
+                CallStackEntry callstackEntry = new CallStackEntry();
+                callstackEntry.method = matches[i].Groups[1].Value;
+                callstackEntry.file = matches[i].Groups[2].Value;
+                int.TryParse(matches[i].Groups[3].Value, out callstackEntry.line);
+
+                newEntry.callstack[i] = callstackEntry;
+            }
+
+            newEntry.message = headerMatch.Groups[1].Value;
+
+            return newEntry;
+        }
+
         /// <summary>
         /// <summary>
         /// Triggered by the runtime when a new message is added to the debug log.
         /// Triggered by the runtime when a new message is added to the debug log.
         /// </summary>
         /// </summary>