Fix crash using Flatten Visible when the active layer is a child of a group

This commit is contained in:
David Capello 2020-02-25 14:10:50 -03:00
parent 54bb39a9d3
commit 53cb226f09
3 changed files with 22 additions and 4 deletions

View File

@ -394,13 +394,17 @@ void DocView::onAddLayer(DocEvent& ev)
}
}
// TODO why note move this code to Editor::onBeforeRemoveLayer?
void DocView::onBeforeRemoveLayer(DocEvent& ev)
{
Sprite* sprite = ev.sprite();
Layer* layer = ev.layer();
// If the layer that was removed is the selected one
if (layer == m_editor->layer()) {
// If the layer that was removed is the selected one in the editor,
// or is an ancestor of the selected one.
if ((m_editor->layer() == layer) ||
(m_editor->layer() &&
m_editor->layer()->hasAncestor(layer))) {
LayerGroup* parent = layer->parent();
Layer* layer_select = NULL;

View File

@ -1,5 +1,6 @@
// Aseprite Document Library
// Copyright (c) 2001-2018 David Capello
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -176,6 +177,17 @@ bool Layer::isEditableHierarchy() const
return true;
}
bool Layer::hasAncestor(const Layer* ancestor) const
{
Layer* it = parent();
while (it) {
if (it == ancestor)
return true;
it = it->parent();
}
return false;
}
Cel* Layer::cel(frame_t frame) const
{
return nullptr;

View File

@ -1,5 +1,6 @@
// Aseprite Document Library
// Copyright (c) 2001-2018 David Capello
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -88,6 +89,7 @@ namespace doc {
bool isVisibleHierarchy() const;
bool isEditableHierarchy() const;
bool hasAncestor(const Layer* ancestor) const;
void setBackground(bool state) { switchFlags(LayerFlags::Background, state); }
void setVisible (bool state) { switchFlags(LayerFlags::Visible, state); }