From 6f048d10c5348a3b3934de5d415628ffd986b04a Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 17 Jun 2020 17:13:37 -0300 Subject: [PATCH] lua: Fix crash using Selection:deselect() when there is no selection Fixes https://community.aseprite.org/t/6169 --- src/app/cmd/deselect_mask.cpp | 12 +++++++----- src/app/script/selection_class.cpp | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app/cmd/deselect_mask.cpp b/src/app/cmd/deselect_mask.cpp index f661ed751..39da945cf 100644 --- a/src/app/cmd/deselect_mask.cpp +++ b/src/app/cmd/deselect_mask.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -35,11 +35,13 @@ void DeselectMask::onUndo() { Doc* doc = document(); - doc->setMask(m_oldMask.get()); - doc->setMaskVisible(true); - doc->notifySelectionChanged(); + if (m_oldMask) { + doc->setMask(m_oldMask.get()); + doc->setMaskVisible(true); + m_oldMask.reset(); + } - m_oldMask.reset(); + doc->notifySelectionChanged(); } size_t DeselectMask::onMemSize() const diff --git a/src/app/script/selection_class.cpp b/src/app/script/selection_class.cpp index f30db6080..4426d9030 100644 --- a/src/app/script/selection_class.cpp +++ b/src/app/script/selection_class.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2015-2018 David Capello // // This program is distributed under the terms of @@ -116,9 +116,11 @@ int Selection_deselect(lua_State* L) Doc* doc = static_cast(sprite->document()); ASSERT(doc); - Tx tx; - tx(new cmd::DeselectMask(doc)); - tx.commit(); + if (doc->isMaskVisible()) { + Tx tx; + tx(new cmd::DeselectMask(doc)); + tx.commit(); + } } else { auto mask = obj->mask(L);