From 20a9ecaebf357387f960f84111ee0dc8ba8cbca0 Mon Sep 17 00:00:00 2001 From: Xam Date: Fri, 17 Apr 2026 18:08:33 -0500 Subject: [PATCH] HLE: CaptureManager: SaveScreenShot: properly handle screenshot image data no way this was working before, and if it did, just pure luck, unsafe blind copy of bytes as is and zero checks. i only tested tomodachi, but should fix all games that were crashing on saving screenshots the crash was happening because the screenshot buffer was bigger than the bitmap buffer, so marshall.copy() was raising an unhandhled expection crashing the emu. on top of this, because the data was just copied as is, the result image was garbled. --- src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs b/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs index bf0c7e9dc..ee1c85895 100644 --- a/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Caps/CaptureManager.cs @@ -118,8 +118,11 @@ namespace Ryujinx.HLE.HOS.Services.Caps } // NOTE: The saved JPEG file doesn't have the limitation in the extra EXIF data. - using var bitmap = new SKBitmap(new SKImageInfo(1280, 720, SKColorType.Rgba8888)); - Marshal.Copy(screenshotData, 0, bitmap.GetPixels(), screenshotData.Length); + using var bitmap = new SKBitmap(new SKImageInfo(1280, 720, SKColorType.Rgba8888, SKAlphaType.Premul)); + int dataLen = screenshotData.Length > bitmap.ByteCount ? bitmap.ByteCount : screenshotData.Length; + + Marshal.Copy(screenshotData, 0, bitmap.GetPixels(), dataLen); + using var data = bitmap.Encode(SKEncodedImageFormat.Jpeg, 80); using var file = File.OpenWrite(filePath); data.SaveTo(file);