1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:47:45 +00:00

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.
This commit is contained in:
Felix Rauch 2021-09-24 21:27:09 +02:00 committed by Linus Groh
parent 9f6a09837b
commit 183a2ec8bd

View file

@ -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();
}
}));