Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
35 changes: 3 additions & 32 deletions plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "SentrySettings.h"

#include "Utils/SentryFileUtils.h"
#include "Utils/SentryScreenshotUtils.h"

#include "Misc/CoreDelegates.h"
#include "Misc/FileHelper.h"
Expand Down Expand Up @@ -42,41 +43,11 @@ TSharedPtr<ISentryId> 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<uint8> 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;
}

Expand Down