Fix crash applying filters (fix #4928)

The program was crashing when applying a filter that as a result
removed the current cel
This commit is contained in:
Martín Capello 2025-01-15 16:35:19 -03:00 committed by David Capello
parent dd654ca2aa
commit d15b585d03
6 changed files with 28 additions and 8 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2025 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -251,7 +251,8 @@ void FilterManagerImpl::apply()
ASSERT(m_reader.context());
m_reader.context()->setCommandResult(result);
init(m_site.cel());
if (m_site.cel())
init(m_site.cel());
}
void FilterManagerImpl::applyToTarget()

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2025 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -100,6 +100,7 @@ public:
doc::Sprite* sprite() { return m_site.sprite(); }
doc::Layer* layer() { return m_site.layer(); }
doc::frame_t frame() { return m_site.frame(); }
doc::Cel* cel() { return m_site.cel(); }
doc::Image* destinationImage() const { return m_dst.get(); }
gfx::Point position() const { return gfx::Point(0, 0); }

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2025 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -166,6 +166,13 @@ void FilterWindow::onApply()
update_screen_for_document(m_filterMgr->document());
restartPreview();
// If there is no cel after applying the filter, then close the window because we cannot
// continue applying it over an empty cel.
if (!m_filterMgr->cel()) {
onCancel();
return;
}
}
void FilterWindow::onOk()

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2018-2025 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -1958,7 +1958,7 @@ void Timeline::onAddCel(DocEvent& ev)
void Timeline::onAfterRemoveCel(DocEvent& ev)
{
invalidateLayer(ev.layer());
ui::execute_now_or_enqueue([this, ev] { invalidateLayer(ev.layer()); });
}
void Timeline::onLayerNameChange(DocEvent& ev)

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2018-2025 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -280,6 +280,14 @@ void execute_from_ui_thread(std::function<void()>&& func)
os::queue_event(ev);
}
void execute_now_or_enqueue(std::function<void()>&& func)
{
if (is_ui_thread())
func();
else
execute_from_ui_thread(std::move(func));
}
bool is_ui_thread()
{
return (main_gui_thread == std::this_thread::get_id());

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2019-2025 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -62,6 +62,9 @@ gfx::Point get_mouse_position();
void set_mouse_position(const gfx::Point& newPos, Display* display);
void execute_from_ui_thread(std::function<void()>&& func);
// If it is called from the UI thread just executes the function, if it is
// called from a different thread, then call execute_from_ui_thread.
void execute_now_or_enqueue(std::function<void()>&& func);
bool is_ui_thread();
#ifdef _DEBUG
void assert_ui_thread();