summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Offenhäuser <offenhaeuser@protonmail.com>2022-10-27 19:49:16 +0200
committerAndreas Kling <kling@serenityos.org>2022-11-19 15:42:08 +0100
commite782d03f96afe96654b1d76c1207e2e77248422b (patch)
tree3d6c1c61885a275289fb9b7d7000bf146e469c13
parentef30073127a8b21958f99da0680433a03afa482f (diff)
downloadserenity-e782d03f96afe96654b1d76c1207e2e77248422b.zip
PDFViewer: Invalidate document when a page fails to load
This fixes an issue where we would show an error message on every subsequent paint event, making it impossible to close or use the application further. Some more architectural work is needed if we want to invalidate the sidebar entries as well.
-rw-r--r--Userland/Applications/PDFViewer/PDFViewer.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/Userland/Applications/PDFViewer/PDFViewer.cpp b/Userland/Applications/PDFViewer/PDFViewer.cpp
index 1125c2bf48..f69383a7cf 100644
--- a/Userland/Applications/PDFViewer/PDFViewer.cpp
+++ b/Userland/Applications/PDFViewer/PDFViewer.cpp
@@ -88,19 +88,17 @@ void PDFViewer::paint_event(GUI::PaintEvent& event)
if (!m_document)
return;
- auto handle_error = [&]<typename T>(PDF::PDFErrorOr<T> maybe_error) {
- if (maybe_error.is_error()) {
- auto error = maybe_error.release_error();
- GUI::MessageBox::show_error(nullptr, String::formatted("Error rendering page:\n{}", error.message()));
- return true;
- }
- return false;
+ auto handle_error = [&](PDF::Error& error) {
+ GUI::MessageBox::show_error(nullptr, String::formatted("Failed to render page:\n{}", error.message()));
+ m_document.clear();
};
if (m_page_view_mode == PageViewMode::Single) {
auto maybe_page = get_rendered_page(m_current_page_index);
- if (handle_error(maybe_page))
+ if (maybe_page.is_error()) {
+ handle_error(maybe_page.error());
return;
+ }
auto page = maybe_page.release_value();
set_content_size(page->size());
@@ -137,8 +135,10 @@ void PDFViewer::paint_event(GUI::PaintEvent& event)
for (size_t page_index = first_page_index; page_index <= last_page_index; page_index++) {
auto maybe_page = get_rendered_page(page_index);
- if (handle_error(maybe_page))
+ if (maybe_page.is_error()) {
+ handle_error(maybe_page.error());
return;
+ }
auto page = maybe_page.release_value();