From 2a908f79df6a1abb67f6c8998bc6b2a7741cbd50 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 5 Apr 2022 20:45:34 -0300 Subject: [PATCH] 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(). --- src/app/commands/cmd_run_script.cpp | 7 +++++-- src/app/script/api_version.h | 2 +- src/app/script/dialog_class.cpp | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/commands/cmd_run_script.cpp b/src/app/commands/cmd_run_script.cpp index 3409ff2308..b04dc48f75 100644 --- a/src/app/commands/cmd_run_script.cpp +++ b/src/app/commands/cmd_run_script.cpp @@ -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 diff --git a/src/app/script/api_version.h b/src/app/script/api_version.h index a1759b2cdf..4f66ee4699 100644 --- a/src/app/script/api_version.h +++ b/src/app/script/api_version.h @@ -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 diff --git a/src/app/script/dialog_class.cpp b/src/app/script/dialog_class.cpp index 07712039c7..8c01b7fdeb 100644 --- a/src/app/script/dialog_class.cpp +++ b/src/app/script/dialog_class.cpp @@ -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(L); // The uservalue of the dialog userdata will contain a table that