Fix crash when a Lua error happens in a Dialog onclose (fix #3237)

This commit is contained in:
David Capello 2022-04-05 23:57:36 -03:00
parent 3ed969ff0a
commit 2594892dd5
3 changed files with 20 additions and 4 deletions

View File

@ -538,8 +538,16 @@ App::~App()
ASSERT(m_instance == this);
#ifdef ENABLE_SCRIPTING
// Destroy scripting engine
m_engine.reset(nullptr);
// Destroy scripting engine calling a method (instead of using
// reset()) because we need to keep the "m_engine" pointer valid
// until the very end, just in case that some Lua error happens
// now and we have to print that error using
// App::instance()->scriptEngine() in some way. E.g. if a Dialog
// onclose event handler fails with a Lua error when we are
// closing the app, a Lua error must be printed, and we need a
// valid m_engine pointer.
m_engine->destroy();
m_engine.reset();
#endif
// Delete file formats.

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -426,11 +426,17 @@ Engine::Engine()
}
Engine::~Engine()
{
ASSERT(L == nullptr);
}
void Engine::destroy()
{
#ifdef ENABLE_UI
close_all_dialogs();
#endif
lua_close(L);
L = nullptr;
}
void Engine::printLastResult()

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -81,6 +81,8 @@ namespace app {
Engine();
~Engine();
void destroy();
EngineDelegate* delegate() { return m_delegate; }
void setDelegate(EngineDelegate* delegate) {
m_delegate = delegate;