fix(color): prevent crash, show error if Lua script uses a deleted LVGL object (#6229)
This commit is contained in:
@@ -319,12 +319,12 @@ void LuaWidget::checkEvents()
|
||||
refresh(nullptr);
|
||||
if (!errorMessage) {
|
||||
if (!callRefs(lsWidgets)) {
|
||||
setErrorMessage("callRefs()");
|
||||
setErrorMessage("function");
|
||||
}
|
||||
}
|
||||
refreshInstructionsPercent = instructionsPercent;
|
||||
} else {
|
||||
// TODO: error handling
|
||||
setErrorMessage("function");
|
||||
}
|
||||
luaScriptManager = save;
|
||||
UNPROTECT_LUA();
|
||||
@@ -375,6 +375,7 @@ void LuaWidget::update()
|
||||
lua_setfield(lsWidgets, -2, option->name);
|
||||
}
|
||||
|
||||
auto save = luaScriptManager;
|
||||
luaScriptManager = this;
|
||||
|
||||
if (lua_pcall(lsWidgets, 2, 0, 0) != 0)
|
||||
@@ -388,17 +389,17 @@ void LuaWidget::update()
|
||||
if (a.x2 >= 0 && a.x1 < LCD_W) {
|
||||
PROTECT_LUA() {
|
||||
if (!callRefs(lsWidgets)) {
|
||||
setErrorMessage("callRefs()");
|
||||
setErrorMessage("function");
|
||||
}
|
||||
} else {
|
||||
// TODO: error handling
|
||||
setErrorMessage("function");
|
||||
}
|
||||
UNPROTECT_LUA();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
luaScriptManager = nullptr;
|
||||
luaScriptManager = save;
|
||||
}
|
||||
|
||||
// Update table on top of Lua stack - set entry with name 'idx' to value 'val'
|
||||
@@ -459,12 +460,13 @@ void LuaWidget::onFullscreen(bool enable)
|
||||
|
||||
void LuaWidget::setErrorMessage(const char* funcName)
|
||||
{
|
||||
constexpr int err_len = 255;
|
||||
|
||||
const char* lua_err = lua_tostring(lsWidgets, -1);
|
||||
TRACE("Error in widget %s %s function: %s", factory->getName(), funcName,
|
||||
lua_err);
|
||||
TRACE("Widget disabled");
|
||||
|
||||
size_t err_len = snprintf(NULL, 0, "ERROR in %s: %s", funcName, lua_err);
|
||||
errorMessage = (char*)malloc(err_len + 1);
|
||||
|
||||
if (errorMessage) {
|
||||
@@ -473,6 +475,11 @@ void LuaWidget::setErrorMessage(const char* funcName)
|
||||
}
|
||||
}
|
||||
|
||||
void LuaWidget::luaShowError()
|
||||
{
|
||||
setErrorMessage("widget");
|
||||
}
|
||||
|
||||
const char* LuaWidget::getErrorMessage() const { return errorMessage; }
|
||||
|
||||
void LuaWidget::refresh(BitmapBuffer* dc)
|
||||
|
||||
Reference in New Issue
Block a user