Fix certain Lua script errors hanging the GUI (#899)

* Fixed a bug where a standalone Lua script w/o a run function will hang the GUI on non-color radios

* Prevent Lua standalone window from opening if Lua failed on load

* Fixed scroll down key in TX12 simulator
Copied key definitions from TX16S

* Fixed the Lua error trying to call nil value when no scripts are loaded.

* I messed up in the previous commit; now it does not freeze and it does not call nil.
This commit is contained in:
Jesper Frickmann
2021-10-15 12:03:23 +11:00
committed by GitHub
parent b1a41438a3
commit ecf386e71f
4 changed files with 18 additions and 12 deletions
@@ -34,8 +34,8 @@ SimulatedUIWidgetTX12::SimulatedUIWidgetTX12(SimulatorInterface *simulator, QWid
act = new RadioUiAction(0, QList<int>() << Qt::Key_Down << Qt::Key_Delete << Qt::Key_Escape << Qt::Key_Backspace, SIMU_STR_HLP_KEYS_EXIT, SIMU_STR_HLP_ACT_EXIT);
addRadioWidget(ui->leftbuttons->addArea(QRect(70, 85, 80, 35), "TX12/left-rtn.png", act));
m_scrollUpAction = new RadioUiAction(-1, QList<int>() << Qt::Key_Minus << Qt::Key_Equal << Qt::Key_Left, SIMU_STR_HLP_KEYS_GO_LFT, SIMU_STR_HLP_ACT_ROT_LFT);
m_scrollDnAction = new RadioUiAction(-1, QList<int>() << Qt::Key_Plus << Qt::Key_Right, SIMU_STR_HLP_KEYS_GO_RGT, SIMU_STR_HLP_ACT_ROT_RGT);
m_scrollUpAction = new RadioUiAction(-1, QList<int>() << Qt::Key_Minus << Qt::Key_Left, SIMU_STR_HLP_KEYS_GO_LFT, SIMU_STR_HLP_ACT_ROT_LFT);
m_scrollDnAction = new RadioUiAction(-1, QList<int>() << Qt::Key_Plus << Qt::Key_Equal, SIMU_STR_HLP_KEYS_GO_RGT, SIMU_STR_HLP_ACT_ROT_RGT);
connectScrollActions();
m_backlightColors << QColor(215, 243, 255); // X7 Blue
+2 -2
View File
@@ -334,8 +334,8 @@ void RadioSdManagerPage::build(FormWindow * window)
std::string fullpath = currentPath + "/" + name;
menu->addLine(STR_EXECUTE_FILE, [=]() {
luaExec(fullpath.c_str());
//TODO: check 'luaState'
StandaloneLuaWindow::instance()->attach(window);
if (luaState != INTERPRETER_RELOAD_PERMANENT_SCRIPTS)
StandaloneLuaWindow::instance()->attach(window);
});
}
#endif
+3 -1
View File
@@ -126,8 +126,10 @@ void RadioToolsPage::rebuild(FormWindow * window)
*((char *)getBasename(toolPath)-1) = '\0';
f_chdir(toolPath);
StandaloneLuaWindow::instance()->attach(window);
luaExec(path_str.c_str());
if (luaState != INTERPRETER_RELOAD_PERMANENT_SCRIPTS)
StandaloneLuaWindow::instance()->attach(window);
return 0;
},
OPAQUE);
+11 -7
View File
@@ -891,6 +891,7 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
if (sid.run == LUA_NOREF) {
TRACE_ERROR("luaLoadScripts(%s): No run function\n", getScriptName(idx));
sid.state = SCRIPT_SYNTAX_ERROR;
initFunction = LUA_NOREF;
}
#if defined(LUA_MODEL_SCRIPTS)
// Get input/output tables for mixer scripts
@@ -908,6 +909,7 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
else {
TRACE_ERROR("luaLoadScripts(%s): The script did not return a table\n", getScriptName(idx));
sid.state = SCRIPT_SYNTAX_ERROR;
initFunction = LUA_NOREF;
}
// Pop the table off the stack
@@ -929,11 +931,7 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
else
TRACE_ERROR("luaLoadScripts(%s): %s\n", getScriptName(idx), lua_tostring(lsScripts, -1));
if (ref == SCRIPT_STANDALONE) {
luaState = INTERPRETER_RELOAD_PERMANENT_SCRIPTS;
luaError(lsScripts, sid.state, true);
return;
}
initFunction = LUA_NOREF;
// Replace the dead coroutine with a new one
lua_pop(L, 1); // Pop the dead coroutine off the main stack
@@ -944,6 +942,12 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
} while(initFunction != LUA_NOREF);
if (ref == SCRIPT_STANDALONE && sid.state != SCRIPT_OK) {
luaState = INTERPRETER_RELOAD_PERMANENT_SCRIPTS;
luaError(lsScripts, sid.state, true);
return;
}
} while(++ref < SCRIPT_STANDALONE);
// Loading has finished - start running scripts
@@ -981,7 +985,7 @@ static bool resumeLua(bool init, bool allowLcdUsage)
luaLcdAllowed = allowLcdUsage;
}
do {
for (; idx < luaScriptsCount; idx++) {
ScriptInternalData & sid = scriptInternalData[idx];
if (sid.state != SCRIPT_OK) continue;
@@ -1155,7 +1159,7 @@ static bool resumeLua(bool init, bool allowLcdUsage)
}
else luaFree(lsScripts, sid);
}
} while (++idx < luaScriptsCount);
} // for
// Toggle between background and foreground scripts
luaLcdAllowed = !luaLcdAllowed;