Skip to content

Commit

Permalink
lua: Dialog() must return nil if there is no UI available
Browse files Browse the repository at this point in the history
This avoids some crashes when running in --batch mode and some script
tries to create a Dialog().
  • Loading branch information
dacap committed Apr 5, 2022
1 parent be7c26d commit 2a908f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/app/commands/cmd_run_script.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/script/api_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion src/app/script/dialog_class.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2a908f7

Please sign in to comment.