diff options
| author | 2019-04-05 19:45:10 -0400 | |
|---|---|---|
| committer | 2019-04-05 19:54:53 -0400 | |
| commit | c0e320ad0da51b5245a071cecbfcdae7a461522f (patch) | |
| tree | 12e300dcfa6660564d1fabb0f9108b153cf08c91 /src | |
| parent | yuzu/debugger/graphics_surface: Tidy up SaveSurface (diff) | |
| download | yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.tar.gz yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.tar.xz yuzu-c0e320ad0da51b5245a071cecbfcdae7a461522f.zip | |
yuzu/debugger/graphics_surface: Display error messages for file I/O errors
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/debugger/graphics/graphics_surface.cpp | 32 |
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 @@ | |||
| 7 | #include <QDebug> | 7 | #include <QDebug> |
| 8 | #include <QFileDialog> | 8 | #include <QFileDialog> |
| 9 | #include <QLabel> | 9 | #include <QLabel> |
| 10 | #include <QMessageBox> | ||
| 10 | #include <QMouseEvent> | 11 | #include <QMouseEvent> |
| 11 | #include <QPushButton> | 12 | #include <QPushButton> |
| 12 | #include <QScrollArea> | 13 | #include <QScrollArea> |
| @@ -477,9 +478,16 @@ void GraphicsSurfaceWidget::SaveSurface() { | |||
| 477 | const QPixmap* const pixmap = surface_picture_label->pixmap(); | 478 | const QPixmap* const pixmap = surface_picture_label->pixmap(); |
| 478 | ASSERT_MSG(pixmap != nullptr, "No pixmap set"); | 479 | ASSERT_MSG(pixmap != nullptr, "No pixmap set"); |
| 479 | 480 | ||
| 480 | QFile file(filename); | 481 | QFile file{filename}; |
| 481 | file.open(QIODevice::WriteOnly); | 482 | if (!file.open(QIODevice::WriteOnly)) { |
| 482 | pixmap->save(&file, "PNG"); | 483 | QMessageBox::warning(this, tr("Error"), tr("Failed to open file '%1'").arg(filename)); |
| 484 | return; | ||
| 485 | } | ||
| 486 | |||
| 487 | if (!pixmap->save(&file, "PNG")) { | ||
| 488 | QMessageBox::warning(this, tr("Error"), | ||
| 489 | tr("Failed to save surface data to file '%1'").arg(filename)); | ||
| 490 | } | ||
| 483 | } else if (selected_filter == bin_filter) { | 491 | } else if (selected_filter == bin_filter) { |
| 484 | auto& gpu = Core::System::GetInstance().GPU(); | 492 | auto& gpu = Core::System::GetInstance().GPU(); |
| 485 | const std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address); | 493 | const std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address); |
| @@ -487,11 +495,21 @@ void GraphicsSurfaceWidget::SaveSurface() { | |||
| 487 | const u8* const buffer = Memory::GetPointer(*address); | 495 | const u8* const buffer = Memory::GetPointer(*address); |
| 488 | ASSERT_MSG(buffer != nullptr, "Memory not accessible"); | 496 | ASSERT_MSG(buffer != nullptr, "Memory not accessible"); |
| 489 | 497 | ||
| 490 | QFile file(filename); | 498 | QFile file{filename}; |
| 491 | file.open(QIODevice::WriteOnly); | 499 | if (!file.open(QIODevice::WriteOnly)) { |
| 492 | const int size = surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format); | 500 | QMessageBox::warning(this, tr("Error"), tr("Failed to open file '%1'").arg(filename)); |
| 501 | return; | ||
| 502 | } | ||
| 503 | |||
| 504 | const int size = | ||
| 505 | surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format); | ||
| 493 | const QByteArray data(reinterpret_cast<const char*>(buffer), size); | 506 | const QByteArray data(reinterpret_cast<const char*>(buffer), size); |
| 494 | file.write(data); | 507 | if (file.write(data) != data.size()) { |
| 508 | QMessageBox::warning( | ||
| 509 | this, tr("Error"), | ||
| 510 | tr("Failed to completely write surface data to file. The saved data will " | ||
| 511 | "likely be corrupt.")); | ||
| 512 | } | ||
| 495 | } else { | 513 | } else { |
| 496 | UNREACHABLE_MSG("Unhandled filter selected"); | 514 | UNREACHABLE_MSG("Unhandled filter selected"); |
| 497 | } | 515 | } |