From 183a2ec8bd27110fd0534a3771334372baf10dc4 Mon Sep 17 00:00:00 2001 From: Felix Rauch Date: Fri, 24 Sep 2021 21:27:09 +0200 Subject: [PATCH] PixelPaint: Create an empty layer when the last layer is removed Previously, when the last layer got deleted, the active layer was set to nullptr, causing a crash. Now, we create a new transparent background layer with the image dimensions instead. --- Userland/Applications/PixelPaint/MainWidget.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 5cdc1b78a1..b58d88b164 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -529,7 +529,11 @@ void MainWidget::initialize_menubar(GUI::Window& window) auto& next_active_layer = editor->image().layer(active_layer_index > 0 ? active_layer_index - 1 : 0); editor->set_active_layer(&next_active_layer); } else { - editor->set_active_layer(nullptr); + auto layer = PixelPaint::Layer::try_create_with_size(editor->image(), editor->image().size(), "Background"); + VERIFY(layer); + editor->image().add_layer(layer.release_nonnull()); + editor->layers_did_change(); + m_layer_list_widget->select_top_layer(); } }));