summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2019-04-06 01:45:10 +0200
committerLioncash <mathew1800@gmail.com>2019-04-06 01:54:53 +0200
commitc0e320ad0da51b5245a071cecbfcdae7a461522f (patch)
tree12e300dcfa6660564d1fabb0f9108b153cf08c91 /src
parentyuzu/debugger/graphics_surface: Tidy up SaveSurface (diff)
downloadyuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.tar
yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.tar.gz
yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.tar.bz2
yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.tar.lz
yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.tar.xz
yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.tar.zst
yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.zip
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/debugger/graphics/graphics_surface.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/yuzu/debugger/graphics/graphics_surface.cpp b/src/yuzu/debugger/graphics/graphics_surface.cpp
index 31d412ff5..f2d14becf 100644
--- a/src/yuzu/debugger/graphics/graphics_surface.cpp
+++ b/src/yuzu/debugger/graphics/graphics_surface.cpp
@@ -7,6 +7,7 @@
#include <QDebug>
#include <QFileDialog>
#include <QLabel>
+#include <QMessageBox>
#include <QMouseEvent>
#include <QPushButton>
#include <QScrollArea>
@@ -477,9 +478,16 @@ void GraphicsSurfaceWidget::SaveSurface() {
const QPixmap* const pixmap = surface_picture_label->pixmap();
ASSERT_MSG(pixmap != nullptr, "No pixmap set");
- QFile file(filename);
- file.open(QIODevice::WriteOnly);
- pixmap->save(&file, "PNG");
+ QFile file{filename};
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::warning(this, tr("Error"), tr("Failed to open file '%1'").arg(filename));
+ return;
+ }
+
+ if (!pixmap->save(&file, "PNG")) {
+ QMessageBox::warning(this, tr("Error"),
+ tr("Failed to save surface data to file '%1'").arg(filename));
+ }
} else if (selected_filter == bin_filter) {
auto& gpu = Core::System::GetInstance().GPU();
const std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address);
@@ -487,11 +495,21 @@ void GraphicsSurfaceWidget::SaveSurface() {
const u8* const buffer = Memory::GetPointer(*address);
ASSERT_MSG(buffer != nullptr, "Memory not accessible");
- QFile file(filename);
- file.open(QIODevice::WriteOnly);
- const int size = surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format);
+ QFile file{filename};
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::warning(this, tr("Error"), tr("Failed to open file '%1'").arg(filename));
+ return;
+ }
+
+ const int size =
+ surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format);
const QByteArray data(reinterpret_cast<const char*>(buffer), size);
- file.write(data);
+ if (file.write(data) != data.size()) {
+ QMessageBox::warning(
+ this, tr("Error"),
+ tr("Failed to completely write surface data to file. The saved data will "
+ "likely be corrupt."));
+ }
} else {
UNREACHABLE_MSG("Unhandled filter selected");
}