From ade498aa99267948bef1e62f113e35890426fb8b Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Wed, 3 Jul 2024 13:49:37 +0300 Subject: [PATCH 1/7] Set thread-safe user policy for error delegate --- plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h b/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h index d6def2264..3ce85963f 100644 --- a/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h +++ b/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h @@ -15,7 +15,7 @@ class FSentryOutputDeviceError : public FOutputDeviceError FOutputDeviceError* GetParentDevice(); - TMulticastDelegate OnError; + TMulticastDelegate OnError; private: FOutputDeviceError* ParentDevice; From aa26acaa2ff2f2dc822598976c5b7350002c562b Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Wed, 3 Jul 2024 14:06:08 +0300 Subject: [PATCH 2/7] Rename delegate --- plugin-dev/Source/Sentry/Private/SentryOutputDeviceError.cpp | 2 +- plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp | 2 +- plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/SentryOutputDeviceError.cpp b/plugin-dev/Source/Sentry/Private/SentryOutputDeviceError.cpp index 8f2493c06..a1e1172af 100644 --- a/plugin-dev/Source/Sentry/Private/SentryOutputDeviceError.cpp +++ b/plugin-dev/Source/Sentry/Private/SentryOutputDeviceError.cpp @@ -13,7 +13,7 @@ void FSentryOutputDeviceError::Serialize(const TCHAR* V, ELogVerbosity::Type Ver { if(FDebug::HasAsserted()) { - OnError.Broadcast(V); + OnAssert.Broadcast(V); } if (!ParentDevice) diff --git a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp index 6e68ca0fd..151a25e4f 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp @@ -642,7 +642,7 @@ void USentrySubsystem::ConfigureOutputDeviceError() OutputDeviceError = MakeShareable(new FSentryOutputDeviceError(GError)); if (OutputDeviceError) { - OutputDeviceError->OnError.AddLambda([this](const FString& Message) + OutputDeviceError->OnAssert.AddLambda([this](const FString& Message) { SubsystemNativeImpl->CaptureAssertion(TEXT("Assertion failed"), Message); diff --git a/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h b/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h index 3ce85963f..1c2802840 100644 --- a/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h +++ b/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h @@ -15,7 +15,7 @@ class FSentryOutputDeviceError : public FOutputDeviceError FOutputDeviceError* GetParentDevice(); - TMulticastDelegate OnError; + TMulticastDelegate OnAssert; private: FOutputDeviceError* ParentDevice; From ad7e9fe1f7ad5e31c202efd765736dfa42a93898 Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Wed, 3 Jul 2024 14:17:17 +0300 Subject: [PATCH 3/7] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8bad7631..f9a2c6d3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Breaking Changes + +- Rename public `OnError` delegate field in `FSentryOutputDeviceError` class to `OnAssert` + ### Features - On Windows/Linux the SDK can now automatically attach a screenshot to crash events([#582](https://github.com/getsentry/sentry-unreal/pull/582)) @@ -10,6 +14,7 @@ ### Fixes - The SDK no longer intercepts assertions when using crash-reporter ([#586](https://github.com/getsentry/sentry-unreal/pull/586)) +- Fix error output device threading issue ([#589](https://github.com/getsentry/sentry-unreal/pull/589)) ### Dependencies From ca965480ecc2f38a439c79a19903d86e110e2dd2 Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 8 Jul 2024 13:36:04 +0300 Subject: [PATCH 4/7] Add post-loading check before calling beforeSend handler on desktop --- .../Desktop/SentrySubsystemDesktop.cpp | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp b/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp index dfbb6dc92..dcf835555 100644 --- a/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp +++ b/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp @@ -37,6 +37,7 @@ #include "GenericPlatform/GenericPlatformOutputDevices.h" #include "GenericPlatform/GenericPlatformCrashContext.h" #include "UObject/GarbageCollection.h" +#include "UObject/UObjectThreadContext.h" #if PLATFORM_WINDOWS #include "Windows/WindowsPlatformMisc.h" @@ -81,9 +82,14 @@ sentry_value_t HandleBeforeSend(sentry_value_t event, void *hint, void *closure) USentryEvent* EventToProcess = NewObject(); EventToProcess->InitWithNativeImpl(eventDesktop); - return SentrySubsystem->GetBeforeSendHandler()->HandleBeforeSend(EventToProcess, nullptr) - ? event - : sentry_value_new_null(); + USentryEvent* ProcessedEvent = EventToProcess; + if(!FUObjectThreadContext::Get().IsRoutingPostLoad) + { + // Executing UFUNCTION is allowed only when not post-loading + ProcessedEvent = SentrySubsystem->GetBeforeSendHandler()->HandleBeforeSend(EventToProcess, nullptr); + } + + return ProcessedEvent ? event : sentry_value_new_null(); } sentry_value_t HandleBeforeCrash(const sentry_ucontext_t *uctx, sentry_value_t event, void *closure) @@ -102,9 +108,14 @@ sentry_value_t HandleBeforeCrash(const sentry_ucontext_t *uctx, sentry_value_t e USentryEvent* EventToProcess = NewObject(); EventToProcess->InitWithNativeImpl(eventDesktop); - return SentrySubsystem->GetBeforeSendHandler()->HandleBeforeSend(EventToProcess, nullptr) - ? event - : sentry_value_new_null(); + USentryEvent* ProcessedEvent = EventToProcess; + if(!FUObjectThreadContext::Get().IsRoutingPostLoad) + { + // Executing UFUNCTION is allowed only when not post-loading + ProcessedEvent = SentrySubsystem->GetBeforeSendHandler()->HandleBeforeSend(EventToProcess, nullptr); + } + + return ProcessedEvent ? event : sentry_value_new_null(); } else { From 764a25d2d30f822a3308be8a1cafb6e34e9e65dc Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 8 Jul 2024 14:17:57 +0300 Subject: [PATCH 5/7] Set thread-safe user policy for error delegate --- plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h b/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h index 1c2802840..8b569ef1f 100644 --- a/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h +++ b/plugin-dev/Source/Sentry/Public/SentryOutputDeviceError.h @@ -15,7 +15,7 @@ class FSentryOutputDeviceError : public FOutputDeviceError FOutputDeviceError* GetParentDevice(); - TMulticastDelegate OnAssert; + TMulticastDelegate OnAssert; private: FOutputDeviceError* ParentDevice; From 32c65dec6d5880145108c19e8017439dcf0c5a84 Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 8 Jul 2024 15:05:23 +0300 Subject: [PATCH 6/7] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a2c6d3a..09aba1499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ ### Fixes - The SDK no longer intercepts assertions when using crash-reporter ([#586](https://github.com/getsentry/sentry-unreal/pull/586)) -- Fix error output device threading issue ([#589](https://github.com/getsentry/sentry-unreal/pull/589)) +- Fix calling `beforeSend` handler during post-loading ([#589](https://github.com/getsentry/sentry-unreal/pull/589)) ### Dependencies From dedf57238ee59aaa5308d83e5e1b8a659e00d76f Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Wed, 10 Jul 2024 14:46:11 +0300 Subject: [PATCH 7/7] Fix build error after merge --- plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp index 94b24e725..42af22f6c 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp @@ -170,7 +170,7 @@ void USentrySubsystem::Close() { if(OnAssertDelegate.IsValid()) { - OutputDeviceError->OnError.Remove(OnAssertDelegate); + OutputDeviceError->OnAssert.Remove(OnAssertDelegate); OnAssertDelegate.Reset(); }