diff --git a/src/app/file/ase_format.cpp b/src/app/file/ase_format.cpp index 20fd02588..ad19b5cdc 100644 --- a/src/app/file/ase_format.cpp +++ b/src/app/file/ase_format.cpp @@ -1696,8 +1696,12 @@ static void ase_ungroup_all(LayerGroup* group) for (Layer* child : list) { if (child->isGroup()) { - ase_ungroup_all(static_cast(child)); - group->removeLayer(child); + auto* childGroup = static_cast(child); + ase_ungroup_all(childGroup); + group->removeLayer(childGroup); + + ASSERT(childGroup->layersCount() == 0); + delete childGroup; } else if (group != root) { // Create a new name adding all group layer names @@ -1715,11 +1719,6 @@ static void ase_ungroup_all(LayerGroup* group) root->addLayer(child); } } - - if (group != root) { - ASSERT(group->layersCount() == 0); - delete group; - } } } // namespace app