Projectkk2glider/lua bitmap free (#4075)

* Better memory stats (CLI)

* Bitmap buffer overflow check added

* Lua bitmap improvements

* Proper handling of symbolic links in simulator

* S6R Lua script fixes:
 * added progress screen while loading bitmaps
 * memory for bitmaps is now freed when leaving the script

* S6R Lua script: improved bitmap loading

* * Lua Themes and Widgets moved to separate file and separate Lua state
* Stand-alone, mixer and function scripts now behave the same as on Taranis (restarted after the stand-alone script was run)
* both Lua states are independent: Themes and Widgets is initialized only at the start, the other one is initialized before and after the stand-alone script is run

* Better leak test and report in BitmapBuffer

* Re #3318: Lua compiler enabled in simu and Companion simulator. Usage:
 * any time <xxx>.lua file is about to be loaded and if file <xxx>.lua.src exists:
   * load contents of <xxx>.lua.src
   * compile Lua code
   * save compiled code into <xxx>.lua (effectively overwrites existing file)
 * immediately following the compilation the real file loading is done from <xxx>.lua (which by now contains compiled Lua bytecode)
This commit is contained in:
Damjan Adamic
2016-11-28 23:08:18 +01:00
committed by Bertrand Songis
parent ae383cd6a4
commit 92553b6589
18 changed files with 745 additions and 554 deletions
@@ -118,7 +118,7 @@ void menuModelCustomScriptOne(event_t event)
void menuModelCustomScripts(event_t event)
{
lcdDrawNumber(19*FW, 0, luaGetMemUsed(), RIGHT);
lcdDrawNumber(19*FW, 0, luaGetMemUsed(lsScripts), RIGHT);
lcdDrawText(19*FW+1, 0, STR_BYTES);
MENU(STR_MENUCUSTOMSCRIPTS, menuTabModel, MENU_MODEL_CUSTOM_SCRIPTS, MAX_SCRIPTS, { NAVIGATION_LINE_BY_LINE|3/*repeated*/ });
+1 -1
View File
@@ -175,7 +175,7 @@ bool displayTelemetryScreen()
case SCRIPT_SYNTAX_ERROR:
case SCRIPT_PANIC:
case SCRIPT_KILLED:
luaError(state, false);
luaError(lsScripts, state, false);
return true;
}
return false;
+22 -2
View File
@@ -45,7 +45,8 @@ class BitmapBufferBase
format(format),
width(width),
height(height),
data(data)
data(data),
data_end(data + (width * height))
{
}
@@ -74,6 +75,7 @@ class BitmapBufferBase
uint16_t width;
uint16_t height;
T * data;
T * data_end;
};
typedef BitmapBufferBase<const uint16_t> Bitmap;
@@ -82,19 +84,29 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
{
private:
bool dataAllocated;
#if defined(DEBUG)
bool leakReported;
#endif
public:
BitmapBuffer(uint8_t format, uint16_t width, uint16_t height):
BitmapBufferBase<uint16_t>(format, width, height, NULL),
dataAllocated(true)
#if defined(DEBUG)
, leakReported(false)
#endif
{
data = (uint16_t *)malloc(width*height*sizeof(uint16_t));
data_end = data + (width * height);
}
BitmapBuffer(uint8_t format, uint16_t width, uint16_t height, uint16_t * data):
BitmapBufferBase<uint16_t>(format, width, height, data),
dataAllocated(false)
#if defined(DEBUG)
, leakReported(false)
#endif
{
}
@@ -117,7 +129,15 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
inline void drawPixel(display_t * p, display_t value)
{
*p = value;
if (data && (data <= p || p < data_end)) {
*p = value;
}
#if defined(DEBUG)
else if (!leakReported) {
leakReported = true;
TRACE("BitmapBuffer(%p).drawPixel(): buffer overrun, data: %p, written at: %p", this, data, p);
}
#endif
}
inline display_t * getPixelPtr(coord_t x, coord_t y)
@@ -124,7 +124,7 @@ bool menuModelCustomScriptOne(event_t event)
bool menuModelCustomScripts(event_t event)
{
// lcdDrawNumber(19*FW, 0, luaGetMemUsed(), 0);
// lcdDrawNumber(19*FW, 0, luaGetMemUsed(lsScripts), 0);
// lcdDrawText(19*FW+1, 0, STR_BYTES);
MENU(STR_MENUCUSTOMSCRIPTS, MODEL_ICONS, menuTabModel, MENU_MODEL_CUSTOM_SCRIPTS, MAX_SCRIPTS, { NAVIGATION_LINE_BY_LINE|3/*repeated*/ });