lua: Dialog() must return nil if there is no UI available

This avoids some crashes when running in --batch mode and some script
tries to create a Dialog().
This commit is contained in:
David Capello 2022-04-05 20:45:34 -03:00
parent be7c26da5e
commit 2a908f79df
3 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018 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
@ -80,7 +80,10 @@ void RunScriptCommand::onExecute(Context* context)
->scriptEngine()
->evalFile(m_filename, m_params);
ui::Manager::getDefault()->invalidate();
#if ENABLE_UI
if (context->isUIAvailable())
ui::Manager::getDefault()->invalidate();
#endif
}
std::string RunScriptCommand::onGetFriendlyName() const

View File

@ -10,6 +10,6 @@
// Increment this value if the scripting API is modified between two
// released Aseprite versions.
#define API_VERSION 17
#define API_VERSION 18
#endif

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018 David Capello
//
// This program is distributed under the terms of
@ -201,6 +201,10 @@ void Dialog_connect_signal(lua_State* L,
int Dialog_new(lua_State* L)
{
// If we don't have UI, just return nil
if (!App::instance()->isGui())
return 0;
auto dlg = push_new<Dialog>(L);
// The uservalue of the dialog userdata will contain a table that