From c0e320ad0da51b5245a071cecbfcdae7a461522f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Apr 2019 19:45:10 -0400 Subject: [PATCH] yuzu/debugger/graphics_surface: Display error messages for file I/O errors --- .../debugger/graphics/graphics_surface.cpp | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/yuzu/debugger/graphics/graphics_surface.cpp b/src/yuzu/debugger/graphics/graphics_surface.cpp index 31d412ff50..f2d14becf2 100644 --- a/src/yuzu/debugger/graphics/graphics_surface.cpp +++ b/src/yuzu/debugger/graphics/graphics_surface.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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 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(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"); }