From fc0a91ee0e3f944addf71ca8c992a14ab58bfd69 Mon Sep 17 00:00:00 2001 From: Sam Bloomberg Date: Thu, 14 Aug 2025 14:11:34 -0400 Subject: [PATCH 1/3] Add support for unreal's additional crash context scopes --- .../GenericPlatformSentryCrashContext.cpp | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp index 57c978160..ab48cf546 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp @@ -9,6 +9,52 @@ #include "GenericPlatform/GenericPlatformSentryScope.h" +#if WITH_ADDITIONAL_CRASH_CONTEXTS +struct FSentryCrashContextExtendedWriter : public FCrashContextExtendedWriter +{ +public: + TMap Values; + + void OutputBuffer(const TCHAR* Identifier, const FString& Data) + { + Values.Add(Identifier, Data); + } + + virtual void AddBuffer(const TCHAR* Identifier, const uint8* Data, uint32 DataSize) override + { + OutputBuffer(Identifier, FBase64::Encode(Data, DataSize)); + } + + virtual void AddString(const TCHAR* Identifier, const TCHAR* DataStr) override + { + return OutputBuffer(Identifier, DataStr); + } + + static void Apply(TSharedPtr Scope) + { + if (!Scope.IsValid()) + { + return; + } + + FSentryCrashContextExtendedWriter Writer; + FGenericCrashContext::OnAdditionalCrashContextDelegate().Broadcast(Writer); + FAdditionalCrashContextStack::ExecuteProviders(Writer); + + Scope->SetContext(TEXT("AdditionalCrashContext"), Writer.Values); + } +}; +#else +struct FSentryCrashContextExtendedWriter +{ +private: + FSentryCrashContextExtendedWriter() {} + +public: + static void Apply(TSharedPtr Scope) {} +}; +#endif + FGenericPlatformSentryCrashContext::FGenericPlatformSentryCrashContext(TSharedPtr Context) #if UE_VERSION_OLDER_THAN(5, 3, 0) : FGenericCrashContext(Context->CrashType, Context->ErrorMessage) @@ -56,6 +102,8 @@ void FGenericPlatformSentryCrashContext::Apply(TSharedPtr Scope) ContextValues.Add("Memory Stats Total Virtual", FString::Printf(TEXT("%lld"), SessionContext.MemoryStats.TotalVirtual)); Scope->SetContext(TEXT("Crash Info"), ContextValues); + + FSentryCrashContextExtendedWriter::Apply(Scope); } FString FGenericPlatformSentryCrashContext::GetGameData(const FString& Key) From c565458d1bce4dbf0650f51bacd9a68bb4e264d8 Mon Sep 17 00:00:00 2001 From: Sam Bloomberg Date: Thu, 14 Aug 2025 20:42:02 -0400 Subject: [PATCH 2/3] Fix wrong TMap value type --- .../CrashReporter/GenericPlatformSentryCrashContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp index ab48cf546..83d40294c 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp @@ -13,7 +13,7 @@ struct FSentryCrashContextExtendedWriter : public FCrashContextExtendedWriter { public: - TMap Values; + TMap Values; void OutputBuffer(const TCHAR* Identifier, const FString& Data) { From 07a70c5c6ab402f471780b68e25e3cb1de81cdbf Mon Sep 17 00:00:00 2001 From: Sam Bloomberg Date: Fri, 26 Sep 2025 11:15:50 -0400 Subject: [PATCH 3/3] Version check for UE 5.7 --- .../CrashReporter/GenericPlatformSentryCrashContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp index 83d40294c..a9869eb9e 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp @@ -9,7 +9,7 @@ #include "GenericPlatform/GenericPlatformSentryScope.h" -#if WITH_ADDITIONAL_CRASH_CONTEXTS +#if UE_VERSION_NEWER_THAN(5, 7, 0) && WITH_ADDITIONAL_CRASH_CONTEXTS struct FSentryCrashContextExtendedWriter : public FCrashContextExtendedWriter { public: