From 5fcba6e19372720cdab70206ba5ef2de567dc066 Mon Sep 17 00:00:00 2001 From: bsongis Date: Sat, 21 Jun 2014 21:49:26 +0200 Subject: [PATCH] Fixes #1339 --- radio/src/gui/menu_model.cpp | 16 +++++++--------- radio/src/lua.cpp | 34 ++++++---------------------------- radio/src/opentx.h | 6 ++---- 3 files changed, 15 insertions(+), 41 deletions(-) diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 350cebcde..a5eee64eb 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -5357,6 +5357,9 @@ void menuModelCustomScriptOne(uint8_t event) void menuModelCustomScripts(uint8_t event) { + lcd_outdezAtt(19*FW, 0, luaGetMemUsed(), 0); + lcd_puts(19*FW+1, 0, STR_BYTES); + MENU(STR_MENUCUSTOMSCRIPTS, menuTabModel, e_CustomScripts, MAX_SCRIPTS+1, {0, NAVIGATION_LINE_BY_LINE|3/*repeated*/}); uint8_t y; @@ -5390,19 +5393,14 @@ void menuModelCustomScripts(uint8_t event) lcd_putsnAtt(5*FW, y, sd.file, sizeof(sd.file), 0); switch (scriptInternalData[scriptIndex].state) { case SCRIPT_SYNTAX_ERROR: - lcd_puts(28*FW+2, y, "(error)"); + lcd_puts(30*FW+2, y, "(error)"); break; case SCRIPT_KILLED: - lcd_puts(27*FW+2, y, "(killed)"); - break; - case SCRIPT_LEAK: - lcd_puts(29*FW+2, y, "(leak)"); + lcd_puts(29*FW+2, y, "(killed)"); break; default: - lcd_outdezAtt(31*FW, y, luaGetCpuUsed(scriptIndex)); - lcd_putc(31*FW, y, '%'); - lcd_outdezAtt(34*FW+2, y, luaGetMemUsed(scriptIndex)); - lcd_putc(34*FW+2, y, 'k'); + lcd_outdezAtt(34*FW, y, luaGetCpuUsed(scriptIndex)); + lcd_putc(34*FW, y, '%'); break; } scriptIndex++; diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index 733316b2c..e1ac62c81 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -1148,8 +1148,6 @@ int luaLoad(const char *filename, ScriptInternalData & sid, ScriptInputsOutputs { int init = 0; - uint8_t prev_mem = lua_gc(L, LUA_GCCOUNT, 0); - sid.instructions = 0; sid.state = SCRIPT_OK; @@ -1199,8 +1197,6 @@ int luaLoad(const char *filename, ScriptInternalData & sid, ScriptInputsOutputs sid.state = SCRIPT_SYNTAX_ERROR; } - sid.memory = lua_gc(L, LUA_GCCOUNT, 0) - prev_mem; - if (sid.state != SCRIPT_OK) { luaFree(sid); } @@ -1345,9 +1341,6 @@ void luaError(uint8_t error) case SCRIPT_KILLED: msg = "Script killed"; break; - case SCRIPT_LEAK: - msg = "Script memory leak"; - break; } POPUP_WARNING(msg); } @@ -1459,7 +1452,6 @@ void luaTask(uint8_t evt) for (int i=0; i sid.instructions) { sid.instructions = instructionsPercent; } } } } - - if (lua_gc(L, LUA_GCCOUNT, 0) > SCRIPTS_MAX_HEAP) { - uint8_t max_memory = 0; - int8_t max_idx = -1; - for (int i=0; i max_memory && sid.memory > 15) { - max_idx = i; - } - } - if (max_idx >= 0) { - ScriptInternalData & sid = scriptInternalData[max_idx]; - TRACE("Script %d killed", max_idx); - // TODO Global Warning - sid.state = SCRIPT_LEAK; - luaFree(sid); - } - } } lua_gc(L, LUA_GCCOLLECT, 0); #if defined(SIMU) || defined(DEBUG) static int lastgc = 0; - int gc = 1000*lua_gc(L, LUA_GCCOUNT, 0) + lua_gc(L, LUA_GCCOUNTB, 0); + int gc = luaGetMemUsed(); if (gc != lastgc) { lastgc = gc; TRACE("GC Use: %dbytes", gc); @@ -1575,3 +1548,8 @@ void luaTask(uint8_t evt) maxLuaDuration = t0; } } + +int luaGetMemUsed() +{ + return 1000*lua_gc(L, LUA_GCCOUNT, 0) + lua_gc(L, LUA_GCCOUNTB, 0); +} diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 13a2b6127..35d83ecb1 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1450,8 +1450,7 @@ enum AUDIO_SOUNDS { SCRIPT_OK, SCRIPT_NOFILE, SCRIPT_SYNTAX_ERROR, - SCRIPT_KILLED, - SCRIPT_LEAK + SCRIPT_KILLED }; enum ScriptReference { SCRIPT_MIX_FIRST, @@ -1467,7 +1466,6 @@ enum AUDIO_SOUNDS { int run; int background; uint8_t instructions; - uint8_t memory; }; struct ScriptInputsOutputs { uint8_t inputsCount; @@ -1487,7 +1485,7 @@ enum AUDIO_SOUNDS { void luaExec(const char *filename); void luaLoadMixScript(uint8_t index); void luaLoadMixScripts(); - #define luaGetMemUsed(idx) scriptInternalData[idx].memory + int luaGetMemUsed(); #define luaGetCpuUsed(idx) scriptInternalData[idx].instructions bool isTelemetryScriptAvailable(uint8_t index); #define LUA_INIT()