diff --git a/Source/Editor/Windows/DebugLogWindow.cs b/Source/Editor/Windows/DebugLogWindow.cs index ef47fe241..250c9738b 100644 --- a/Source/Editor/Windows/DebugLogWindow.cs +++ b/Source/Editor/Windows/DebugLogWindow.cs @@ -216,7 +216,7 @@ namespace FlaxEditor.Windows /// public void Copy() { - Clipboard.Text = Info.Replace("\n", Environment.NewLine); + Clipboard.Text = Info.Replace("\r\n", "\n").Replace("\n", Environment.NewLine); } public override bool OnMouseDoubleClick(Vector2 location, MouseButton button) @@ -275,7 +275,7 @@ namespace FlaxEditor.Windows private readonly VerticalPanel _entriesPanel; private LogEntry _selected; private readonly int[] _logCountPerGroup = new int[(int)LogGroup.Max]; - private readonly Regex _logRegex = new Regex("at(.*) in (.*):(\\d*)"); + private readonly Regex _logRegex = new Regex("at (.*) in (.*):(line (\\d*)|(\\d*))"); private InterfaceOptions.TimestampsFormats _timestampsFormats; private readonly object _locker = new object(); @@ -508,20 +508,27 @@ namespace FlaxEditor.Windows for (int i = 0; i < matches.Count; i++) { var match = matches[i]; - if (foundStart) + var matchLocation = match.Groups[1].Value.Trim(); + if (matchLocation.StartsWith("FlaxEngine.Debug.", StringComparison.Ordinal)) + { + // C# start + foundStart = true; + } + else if (matchLocation.StartsWith("DebugLog::", StringComparison.Ordinal)) + { + // C++ start + foundStart = true; + } + else if (foundStart) { if (noLocation) { desc.LocationFile = match.Groups[2].Value; - int.TryParse(match.Groups[3].Value, out desc.LocationLine); + int.TryParse(match.Groups[5].Value, out desc.LocationLine); noLocation = false; } fineStackTrace.AppendLine(match.Groups[0].Value); } - else if (match.Groups[1].Value.Trim().StartsWith("FlaxEngine.Debug.", StringComparison.Ordinal)) - { - foundStart = true; - } } desc.Description = fineStackTrace.ToString(); } diff --git a/Source/Engine/Debug/DebugLog.cpp b/Source/Engine/Debug/DebugLog.cpp index 55c17b7f0..9263651b9 100644 --- a/Source/Engine/Debug/DebugLog.cpp +++ b/Source/Engine/Debug/DebugLog.cpp @@ -43,7 +43,7 @@ bool CacheMethods() if (!debugLogHandlerClass) return false; - Internal_SendLog = debugLogHandlerClass->GetMethod("Internal_SendLog", 2); + Internal_SendLog = debugLogHandlerClass->GetMethod("Internal_SendLog", 3); if (!Internal_SendLog) return false; @@ -60,7 +60,7 @@ bool CacheMethods() return false; } -void DebugLog::Log(LogType type, const String& message) +void DebugLog::Log(LogType type, const StringView& message) { if (CacheMethods()) return; @@ -69,15 +69,18 @@ void DebugLog::Log(LogType type, const String& message) MainThreadManagedInvokeAction::ParamsBuilder params; params.AddParam(type); params.AddParam(message, scriptsDomain->GetNative()); +#if BUILD_RELEASE + params.AddParam(StringView::Empty, scriptsDomain->GetNative()); +#else + const String stackTrace = Platform::GetStackTrace(1); + params.AddParam(stackTrace, scriptsDomain->GetNative()); +#endif MainThreadManagedInvokeAction::Invoke(Internal_SendLog, params); } void DebugLog::LogException(MonoObject* exceptionObject) { - if (exceptionObject == nullptr) - return; - - if (CacheMethods()) + if (exceptionObject == nullptr || CacheMethods()) return; MainThreadManagedInvokeAction::ParamsBuilder params; diff --git a/Source/Engine/Debug/DebugLog.h b/Source/Engine/Debug/DebugLog.h index fd05bee7c..2fd210563 100644 --- a/Source/Engine/Debug/DebugLog.h +++ b/Source/Engine/Debug/DebugLog.h @@ -17,13 +17,13 @@ public: /// /// The message type. /// The message. - static void Log(LogType type, const String& message); + static void Log(LogType type, const StringView& message); /// /// A variant of Debug.Log that logs a warning message to the console. /// /// The text message to display. - FORCE_INLINE static void Log(const String& message) + FORCE_INLINE static void Log(const StringView& message) { Log(LogType::Info, message); } @@ -32,7 +32,7 @@ public: /// A variant of Debug.Log that logs a warning message to the console. /// /// The text message to display. - FORCE_INLINE static void LogWarning(const String& message) + FORCE_INLINE static void LogWarning(const StringView& message) { Log(LogType::Warning, message); } @@ -41,7 +41,7 @@ public: /// A variant of Debug.Log that logs a error message to the console. /// /// The text message to display. - FORCE_INLINE static void LogError(const String& message) + FORCE_INLINE static void LogError(const StringView& message) { Log(LogType::Error, message); } diff --git a/Source/Engine/Engine/DebugLogHandler.cs b/Source/Engine/Engine/DebugLogHandler.cs index 986d48a3a..bf9a3bc02 100644 --- a/Source/Engine/Engine/DebugLogHandler.cs +++ b/Source/Engine/Engine/DebugLogHandler.cs @@ -47,9 +47,16 @@ namespace FlaxEngine SendLog?.Invoke(logType, message, context, stackTrace); } - internal static void Internal_SendLog(LogType type, string message) + internal static void Internal_SendLog(LogType logType, string message, string stackTrace) { - Debug.Logger.Log(type, message); + if (message == null) + return; + var logger = Debug.Logger; + if (logger.IsLogTypeAllowed(logType)) + { + Internal_Log(logType, message, IntPtr.Zero, stackTrace); + ((DebugLogHandler)logger.LogHandler).SendLog?.Invoke(logType, message, null, stackTrace); + } } internal static void Internal_SendLogException(Exception exception) diff --git a/Source/Engine/Scripting/MainThreadManagedInvokeAction.h b/Source/Engine/Scripting/MainThreadManagedInvokeAction.h index 5af5e5f28..71ea24595 100644 --- a/Source/Engine/Scripting/MainThreadManagedInvokeAction.h +++ b/Source/Engine/Scripting/MainThreadManagedInvokeAction.h @@ -77,12 +77,24 @@ public: AddParam(val); } + FORCE_INLINE void AddParam(const StringView& value) + { + MonoString* val = MUtils::ToString(value); + AddParam(val); + } + FORCE_INLINE void AddParam(const String& value, MonoDomain* domain) { MonoString* val = MUtils::ToString(value, domain); AddParam(val); } + FORCE_INLINE void AddParam(const StringView& value, MonoDomain* domain) + { + MonoString* val = MUtils::ToString(value, domain); + AddParam(val); + } + void GetParams(void* params[8]) { for (int32 i = 0; i < Count; i++)