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)) diff --git a/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp index 620c96be8..c85877692 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" @@ -42,41 +43,11 @@ TSharedPtr FMacSentrySubsystem::CaptureEnsure(const FString& type, co FString FMacSentrySubsystem::TryCaptureScreenshot() const { - NSWindow* MainWindow = [NSApp mainWindow]; - if (!MainWindow) + const FString ScreenshotPath = GetScreenshotPath(); + if (!SentryScreenshotUtils::CaptureScreenshot(ScreenshotPath)) { - 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(""); - } - return ScreenshotPath; }