mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 17:25:13 +03:00
BMP are read on the stack to avoid a malloc. Lua memory displayed when
pressing [Menu Long]
This commit is contained in:
parent
687ddd8f4d
commit
950f651af9
4 changed files with 30 additions and 23 deletions
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
const pm_char * bmpLoad(bmp_ptr_t &bmp, const char *filename, const xcoord_t width, const uint8_t height)
|
const pm_char * bmpLoad(uint8_t *bmp, const char *filename, const xcoord_t width, const uint8_t height)
|
||||||
{
|
{
|
||||||
FIL bmpFile;
|
FIL bmpFile;
|
||||||
UINT read;
|
UINT read;
|
||||||
|
@ -147,10 +147,6 @@ const pm_char * bmpLoad(bmp_ptr_t &bmp, const char *filename, const xcoord_t wid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bmp == NULL) {
|
|
||||||
bmp = (uint8_t *)malloc(2+w*((h+7)/8)*4);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *dest = bmp;
|
uint8_t *dest = bmp;
|
||||||
|
|
||||||
*dest++ = w;
|
*dest++ = w;
|
||||||
|
|
|
@ -803,7 +803,7 @@ void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, LcdFlags att)
|
||||||
|
|
||||||
void lcd_vline(xcoord_t x, int8_t y, int8_t h)
|
void lcd_vline(xcoord_t x, int8_t y, int8_t h)
|
||||||
{
|
{
|
||||||
lcd_vlineStip(x, y, h, 0xff);
|
lcd_vlineStip(x, y, h, SOLID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_invert_line(int8_t y)
|
void lcd_invert_line(int8_t y)
|
||||||
|
|
|
@ -257,8 +257,7 @@ void lcdSetContrast();
|
||||||
void lcdRefresh();
|
void lcdRefresh();
|
||||||
|
|
||||||
#if defined(PCBTARANIS)
|
#if defined(PCBTARANIS)
|
||||||
typedef uint8_t * bmp_ptr_t;
|
const pm_char * bmpLoad(uint8_t *dest, const char *filename, const xcoord_t width, const uint8_t height);
|
||||||
const pm_char * bmpLoad(bmp_ptr_t &dest, const char *filename, const xcoord_t width, const uint8_t height);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BOOT)
|
#if defined(BOOT)
|
||||||
|
|
|
@ -277,12 +277,10 @@ static int luaLcdDrawPixmap(lua_State *L)
|
||||||
int x = luaL_checkinteger(L, 1);
|
int x = luaL_checkinteger(L, 1);
|
||||||
int y = luaL_checkinteger(L, 2);
|
int y = luaL_checkinteger(L, 2);
|
||||||
const char * filename = luaL_checkstring(L, 3);
|
const char * filename = luaL_checkstring(L, 3);
|
||||||
// TODO int att = luaL_checkinteger(L, 4);
|
uint8_t bitmap[2+LCD_W/2*LCD_H/2]; // width max is LCD_W/2 pixels for saving stack and avoid a malloc here
|
||||||
bmp_ptr_t bitmap = 0;
|
const pm_char * error = bmpLoad(bitmap, filename, LCD_W/2, LCD_H);
|
||||||
const pm_char * error = bmpLoad(bitmap, filename, LCD_W, LCD_H);
|
if (!error) {
|
||||||
if (bitmap && !error) {
|
|
||||||
lcd_bmp(x, y, bitmap);
|
lcd_bmp(x, y, bitmap);
|
||||||
free(bitmap);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1242,6 +1240,7 @@ void luaExec(const char *filename)
|
||||||
void luaTask(uint8_t evt)
|
void luaTask(uint8_t evt)
|
||||||
{
|
{
|
||||||
lcd_locked = false;
|
lcd_locked = false;
|
||||||
|
static uint8_t luaDisplayStatistics = false;
|
||||||
|
|
||||||
if (luaState & LUASTATE_STANDALONE_SCRIPT_RUNNING) {
|
if (luaState & LUASTATE_STANDALONE_SCRIPT_RUNNING) {
|
||||||
// standalone script
|
// standalone script
|
||||||
|
@ -1271,18 +1270,20 @@ void luaTask(uint8_t evt)
|
||||||
else {
|
else {
|
||||||
int scriptResult = lua_tointeger(L, -1);
|
int scriptResult = lua_tointeger(L, -1);
|
||||||
lua_pop(L, 1); /* pop returned value */
|
lua_pop(L, 1); /* pop returned value */
|
||||||
if (scriptResult == 0) {
|
if (scriptResult != 0) {
|
||||||
if (lua_gc(L, LUA_GCCOUNT, 0) > SCRIPTS_MAX_HEAP) {
|
|
||||||
TRACE("Script memory leak");
|
|
||||||
standaloneScript.state = SCRIPT_LEAK;
|
|
||||||
luaState = LUASTATE_RELOAD_MODEL_SCRIPTS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
TRACE("Script finished with status %d", scriptResult);
|
TRACE("Script finished with status %d", scriptResult);
|
||||||
standaloneScript.state = SCRIPT_NOFILE;
|
standaloneScript.state = SCRIPT_NOFILE;
|
||||||
luaState = LUASTATE_RELOAD_MODEL_SCRIPTS;
|
luaState = LUASTATE_RELOAD_MODEL_SCRIPTS;
|
||||||
}
|
}
|
||||||
|
else if (luaDisplayStatistics) {
|
||||||
|
int gc = 1000*lua_gc(L, LUA_GCCOUNT, 0) + lua_gc(L, LUA_GCCOUNTB, 0);
|
||||||
|
lcd_hline(0, 7*FH-1, lcdLastPos+FW, ERASE);
|
||||||
|
lcd_puts(0, 7*FH, "GV Use: ");
|
||||||
|
lcd_outdezAtt(lcdLastPos, 7*FH, gc, LEFT);
|
||||||
|
lcd_putc(lcdLastPos, 7*FH, 'b');
|
||||||
|
lcd_hline(0, 7*FH-2, lcdLastPos+FW, FORCE);
|
||||||
|
lcd_vlineStip(lcdLastPos+FW, 7*FH-2, FH+2, SOLID, FORCE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1301,6 +1302,10 @@ void luaTask(uint8_t evt)
|
||||||
standaloneScript.state = SCRIPT_NOFILE;
|
standaloneScript.state = SCRIPT_NOFILE;
|
||||||
luaState = LUASTATE_RELOAD_MODEL_SCRIPTS;
|
luaState = LUASTATE_RELOAD_MODEL_SCRIPTS;
|
||||||
}
|
}
|
||||||
|
else if (evt == EVT_KEY_LONG(KEY_MENU)) {
|
||||||
|
killEvents(evt);
|
||||||
|
luaDisplayStatistics = !luaDisplayStatistics;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1376,7 +1381,14 @@ void luaTask(uint8_t evt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TRACE("Before GC COLLECT gc=%d", lua_gc(L, LUA_GCCOUNT, 0));
|
|
||||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||||
// TRACE("After GC COLLECT gc=%d", lua_gc(L, LUA_GCCOUNT, 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);
|
||||||
|
if (gc != lastgc) {
|
||||||
|
lastgc = gc;
|
||||||
|
TRACE("GC Use: %dbytes", gc);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue