diff --git a/CHANGELOG.md b/CHANGELOG.md index 66db458b5..c1fbd97ad 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 calling `beforeSend` handler during post-loading ([#589](https://github.com/getsentry/sentry-unreal/pull/589)) - Fix crash when re-initializing Sentry ([#594](https://github.com/getsentry/sentry-unreal/pull/594)) ### Dependencies 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 { 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 3b1aa493c..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(); } @@ -665,7 +665,8 @@ void USentrySubsystem::ConfigureOutputDeviceError() OutputDeviceError = MakeShareable(new FSentryOutputDeviceError(GError)); if (OutputDeviceError) { - OnAssertDelegate = OutputDeviceError->OnError.AddLambda([this](const FString& Message) + OnAssertDelegate = 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 d6def2264..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 OnError; + TMulticastDelegate OnAssert; private: FOutputDeviceError* ParentDevice;