diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.cpp index 57c978160..a9869eb9e 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 UE_VERSION_NEWER_THAN(5, 7, 0) && 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)