From 695aa291f571945fc8c43c9e1c84fe9369ff9b0d Mon Sep 17 00:00:00 2001 From: mujacica Date: Tue, 5 Aug 2025 10:51:50 +0200 Subject: [PATCH 1/5] Use the Screenshot utils to capture Screenshot on Mac, fixing deprecated function use --- .../Sentry/Private/Mac/MacSentrySubsystem.cpp | 40 ++----------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp index 620c96be8..cf6613527 100644 --- a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp @@ -9,6 +9,7 @@ #include "SentrySettings.h" #include "Utils/SentryFileUtils.h" +#include "Utils/SentryScreenshotUtils.h" #include "Misc/CoreDelegates.h" #include "Misc/FileHelper.h" @@ -41,42 +42,9 @@ TSharedPtr FMacSentrySubsystem::CaptureEnsure(const FString& type, co } FString FMacSentrySubsystem::TryCaptureScreenshot() const -{ - NSWindow* MainWindow = [NSApp mainWindow]; - if (!MainWindow) - { - UE_LOG(LogSentrySdk, Error, TEXT("No main window found!")); - return FString(""); - } - - NSRect WindowRect = [MainWindow frame]; - CGWindowID WindowID = (CGWindowID)[MainWindow windowNumber]; - CGImageRef ScreenshotRef = CGWindowListCreateImage(WindowRect, kCGWindowListOptionIncludingWindow, WindowID, kCGWindowImageDefault); - - if (!ScreenshotRef) - { - UE_LOG(LogSentrySdk, Error, TEXT("Failed to capture screenshot - invalid ScreenshotRef.")); - return FString(""); - } - - NSBitmapImageRep* BitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:ScreenshotRef]; - NSData* ImageData = [BitmapRep representationUsingType:NSBitmapImageFileTypePNG properties:@{}]; - - TArray ImageBytes; - uint32 SavedSize = (uint32)[ImageData length]; - ImageBytes.AddUninitialized(SavedSize); - FPlatformMemory::Memcpy(ImageBytes.GetData(), [ImageData bytes], SavedSize); - - CGImageRelease(ScreenshotRef); - - FString ScreenshotPath = GetScreenshotPath(); - - if (!FFileHelper::SaveArrayToFile(ImageBytes, *ScreenshotPath)) - { - UE_LOG(LogSentrySdk, Error, TEXT("Failed to save screenshot to: %s"), *ScreenshotPath); - return FString(""); - } - +{ + const FString ScreenshotPath = GetScreenshotPath(); + SentryScreenshotUtils::CaptureScreenshot(ScreenshotPath); return ScreenshotPath; } From 5139473fdd4c45d7729e58ff6da364527b1cc564 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 5 Aug 2025 08:52:33 +0000 Subject: [PATCH 2/5] Format code --- plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp index cf6613527..c1bd0052d 100644 --- a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp @@ -42,7 +42,7 @@ TSharedPtr FMacSentrySubsystem::CaptureEnsure(const FString& type, co } FString FMacSentrySubsystem::TryCaptureScreenshot() const -{ +{ const FString ScreenshotPath = GetScreenshotPath(); SentryScreenshotUtils::CaptureScreenshot(ScreenshotPath); return ScreenshotPath; From 4d184ea826d0910f93e4d00a4d0b9dc3fe4d4a00 Mon Sep 17 00:00:00 2001 From: mujacica Date: Tue, 5 Aug 2025 11:00:32 +0200 Subject: [PATCH 3/5] Update Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ed9fc285..a0858f182 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Removed usage of deprecated `CGWindowListCreateImage` function on Mac. Replaced with Sentry Screenshot Utils ([#1034](https://github.com/getsentry/sentry-unreal/pull/1034/)) + ### Dependencies - Bump Java SDK (Android) from v8.17.0 to v8.18.0 ([#1031](https://github.com/getsentry/sentry-unreal/pull/1031)) From 263cffa7298b4e17ed773fd62da7820213205755 Mon Sep 17 00:00:00 2001 From: mujacica Date: Tue, 5 Aug 2025 11:21:40 +0200 Subject: [PATCH 4/5] Only send Screenshot Path when capturing was successful --- plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp index c1bd0052d..8a5ec409d 100644 --- a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp @@ -44,7 +44,9 @@ TSharedPtr FMacSentrySubsystem::CaptureEnsure(const FString& type, co FString FMacSentrySubsystem::TryCaptureScreenshot() const { const FString ScreenshotPath = GetScreenshotPath(); - SentryScreenshotUtils::CaptureScreenshot(ScreenshotPath); + if (!SentryScreenshotUtils::CaptureScreenshot(ScreenshotPath)) { + return FString(""); + } return ScreenshotPath; } From 82701828892f582b4eabae7cf084559c2db20a41 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 5 Aug 2025 09:21:59 +0000 Subject: [PATCH 5/5] Format code --- plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp index 8a5ec409d..c85877692 100644 --- a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp @@ -44,7 +44,8 @@ TSharedPtr FMacSentrySubsystem::CaptureEnsure(const FString& type, co FString FMacSentrySubsystem::TryCaptureScreenshot() const { const FString ScreenshotPath = GetScreenshotPath(); - if (!SentryScreenshotUtils::CaptureScreenshot(ScreenshotPath)) { + if (!SentryScreenshotUtils::CaptureScreenshot(ScreenshotPath)) + { return FString(""); } return ScreenshotPath;