From 0da1353c8012c16bdc736d08824ff27cbd87b351 Mon Sep 17 00:00:00 2001 From: Aziz Berkay Yesilyurt Date: Thu, 8 Jul 2021 00:04:50 +0200 Subject: [PATCH] Userland: Keep ImageViewer window size the same while zooming in ImageViewer window kept growing while zooming in, which causes out of memory error and crashes the application. Now, only the image content is rescaled and the window size is preserved. We also open the display window as the same size as the image, which may cause a similar issue for very large image files. This is prevented by limiting the maximum window size to be the screen size. --- Userland/Applications/ImageViewer/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/ImageViewer/main.cpp b/Userland/Applications/ImageViewer/main.cpp index f6cb3f1680..d05f8284b4 100644 --- a/Userland/Applications/ImageViewer/main.cpp +++ b/Userland/Applications/ImageViewer/main.cpp @@ -92,9 +92,11 @@ int main(int argc, char** argv) if (window->is_maximized()) return; - auto w = max(window->width(), rect.width() + 4); - auto h = max(window->height(), rect.height() + widget.toolbar_height() + 6); - window->resize(w, h); + if (scale == 100) { + auto w = min(GUI::Desktop::the().rect().width(), rect.width() + 4); + auto h = min(GUI::Desktop::the().rect().height(), rect.height() + widget.toolbar_height() + 6); + window->resize(w, h); + } }; widget.on_drop = [&](auto& event) { window->move_to_front();