From b36e55446fc7c849bf9f28ee53ba50e194810521 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 24 Jan 2025 20:15:17 +0100 Subject: [PATCH] Add `Engine::ReportCrash` event for custom crash reporting or handling --- Source/Engine/Engine/Engine.cpp | 1 + Source/Engine/Engine/Engine.h | 5 +++++ Source/Engine/Platform/Base/PlatformBase.cpp | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp index 17dc8d333..92e29c78e 100644 --- a/Source/Engine/Engine/Engine.cpp +++ b/Source/Engine/Engine/Engine.cpp @@ -71,6 +71,7 @@ Action Engine::Draw; Action Engine::Pause; Action Engine::Unpause; Action Engine::RequestingExit; +Delegate Engine::ReportCrash; FatalErrorType Engine::FatalError = FatalErrorType::None; bool Engine::IsRequestingExit = false; int32 Engine::ExitCode = 0; diff --git a/Source/Engine/Engine/Engine.h b/Source/Engine/Engine/Engine.h index 692ff494b..1ae590d28 100644 --- a/Source/Engine/Engine/Engine.h +++ b/Source/Engine/Engine/Engine.h @@ -83,6 +83,11 @@ public: /// API_EVENT() static Action RequestingExit; + /// + /// The custom handler for engine crash handling and reporting. Can be used to override default message box with a custom one or send crash report to telemetry service. Args are: error message and context pointer (for stack-trace access). + /// + API_EVENT() static Delegate ReportCrash; + /// /// The current state of the fatal error. Set to None if no error occurred yet. /// diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp index 31830060f..6770cb9eb 100644 --- a/Source/Engine/Platform/Base/PlatformBase.cpp +++ b/Source/Engine/Platform/Base/PlatformBase.cpp @@ -372,7 +372,10 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er } // Show error message - Error(msg); + if (Engine::ReportCrash.IsBinded()) + Engine::ReportCrash(msg, context); + else + Error(msg); // Only main thread can call exit directly if (IsInMainThread())