-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opt-in screenshot attachment for crash events captured on Windows…
…/Linux (#582) * Add screenshot attachment for desktop crash events * Fix includes * Fix more includes * Fix indents * Add ability to capture screenshot including game UI * Update snapshot * Add missing include * Update changelog * Update CHANGELOG.md Co-authored-by: Stefan Jandl <[email protected]> * Remove redundant variable --------- Co-authored-by: Stefan Jandl <[email protected]>
- Loading branch information
1 parent
e26f8d4
commit 4dc30df
Showing
8 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
plugin-dev/Source/Sentry/Private/Utils/SentryScreenshotUtils.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2024 Sentry. All Rights Reserved. | ||
|
||
#include "SentryScreenshotUtils.h" | ||
|
||
#include "HighResScreenshot.h" | ||
#include "SentryDefines.h" | ||
|
||
#include "Engine/Engine.h" | ||
#include "ImageUtils.h" | ||
#include "UnrealClient.h" | ||
#include "Misc/FileHelper.h" | ||
#include "Engine/GameViewportClient.h" | ||
#include "Framework/Application/SlateApplication.h" | ||
|
||
bool SentryScreenshotUtils::CaptureScreenshot(const FString& ScreenshotSavePath) | ||
{ | ||
if (!GEngine || !GEngine->GameViewport) | ||
{ | ||
UE_LOG(LogSentrySdk, Error, TEXT("GameViewport required for screenshot capturing is not valid")); | ||
return false; | ||
} | ||
|
||
UGameViewportClient* GameViewportClient = GEngine->GameViewport; | ||
if (!GameViewportClient) | ||
{ | ||
UE_LOG(LogSentrySdk, Error, TEXT("Game Viewport Client required for screenshot capturing is not valid")); | ||
return false; | ||
} | ||
|
||
FIntVector ViewportSize(GameViewportClient->Viewport->GetSizeXY().X, GameViewportClient->Viewport->GetSizeXY().Y, 0); | ||
|
||
TArray<FColor> Bitmap; | ||
|
||
if (!FSlateApplication::IsInitialized()) | ||
{ | ||
UE_LOG(LogSentrySdk, Error, TEXT("Slate application required for screenshot capturing is not initialized")); | ||
return false; | ||
} | ||
|
||
TSharedPtr<SWindow> WindowPtr = GameViewportClient->GetWindow(); | ||
TSharedRef<SWidget> WindowRef = WindowPtr.ToSharedRef(); | ||
|
||
bool bScreenshotSuccessful = FSlateApplication::Get().TakeScreenshot(WindowRef, Bitmap, ViewportSize); | ||
if (!bScreenshotSuccessful) | ||
{ | ||
UE_LOG(LogSentrySdk, Error, TEXT("Failed to capture screenshot")); | ||
return false; | ||
} | ||
|
||
GetHighResScreenshotConfig().MergeMaskIntoAlpha(Bitmap, FIntRect()); | ||
|
||
TArray64<uint8> CompressedBitmap; | ||
FImageUtils::PNGCompressImageArray(ViewportSize.X, ViewportSize.Y, Bitmap, CompressedBitmap); | ||
FFileHelper::SaveArrayToFile(CompressedBitmap, *ScreenshotSavePath); | ||
|
||
UE_LOG(LogSentrySdk, Log, TEXT("Screenshot saved to: %s"), *ScreenshotSavePath); | ||
|
||
return true; | ||
} |
11 changes: 11 additions & 0 deletions
11
plugin-dev/Source/Sentry/Private/Utils/SentryScreenshotUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) 2024 Sentry. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
|
||
class SentryScreenshotUtils | ||
{ | ||
public: | ||
static bool CaptureScreenshot(const FString& ScreenshotSavePath); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters