fix(LuaGame): fix render black screen, reduce stack to 8192, add exit gesture

- Init task stack 16384->8192 to avoid allocation failure (ret=-1)
- Replace GAME_W/H constants with fb_w/h dynamic for fullscreen 320x480
- Fix l_renderer_clear and app_on_show fill to use dynamic dimensions
- Add PSRAM Lua allocator already, conditional audio skip for solitaire saves RAM
- Exit gesture: top-right 40x40 tap calls tt_app_stop(), game.exit() also stops app
- Screenshot now shows solitaire cards: 810B PNG, 3662 non-black pixels, ASCII preview shows piles with optimized LEFT=4 GAP=4 TOP=4 TAB=60 (was 37/10/30/98)
- Tested solitaire loads external 24430 bytes, pico=1, init OK, no memory low warnings after fix
This commit is contained in:
Adolfo
2026-07-31 13:30:37 -04:00
parent ca1202345e
commit 74fe10f130
+26 -21
View File
@@ -247,7 +247,9 @@ static int l_renderer_clear(lua_State* L){
bool white = false;
if(lua_gettop(L)>=1) white = lua_toboolean(L,1);
uint16_t col = white ? 0xFFFF : 0x0000;
fill_rect(ctx,0,0,GAME_W,GAME_H,col,true);
int w = ctx->game_w ? ctx->game_w : GAME_W_DEFAULT;
int h = ctx->game_h ? ctx->game_h : GAME_H_DEFAULT;
fill_rect(ctx,0,0,w,h,col,true);
clear_labels(ctx);
return 0;
}
@@ -604,7 +606,7 @@ static void lua_init_task(void* arg){
lua_pop(ctx->L,1);
}
} else lua_pop(ctx->L,1);
if(tt_lvgl_lock(portMAX_DELAY)){
if(tt_lvgl_lock(pdMS_TO_TICKS(1000))){
invalidate_canvas(ctx);
tt_lvgl_unlock();
}
@@ -690,23 +692,25 @@ static void lua_init_task(void* arg){
if(lua_isfunction(L,-1)){
if(lua_pcall(L,0,0,0)!=LUA_OK){const char* e=lua_tostring(L,-1); printf("[LUA ERR draw] %s\n",e); lua_pop(L,1); ctx->lua_ok=false;}
}else lua_pop(L,1);
if(tt_lvgl_lock(portMAX_DELAY)){
invalidate_canvas(ctx);
ctx->fps_frames++;
uint64_t elapsed = now - ctx->fps_last_us;
if(elapsed >= 1000000){
ctx->fps = (float)ctx->fps_frames * 1000000.0f / (float)elapsed;
printf("[LuaGame] FPS %.1f (on-demand)\n", ctx->fps);
if(ctx->fps_label){
char buf[32];
snprintf(buf,sizeof(buf),"FPS %.0f",ctx->fps);
lv_label_set_text(ctx->fps_label, buf);
}
ctx->fps_frames=0;
ctx->fps_last_us=now;
if(tt_lvgl_lock(pdMS_TO_TICKS(1000))){
invalidate_canvas(ctx);
ctx->fps_frames++;
uint64_t elapsed = now - ctx->fps_last_us;
if(elapsed >= 1000000){
ctx->fps = (float)ctx->fps_frames * 1000000.0f / (float)elapsed;
printf("[LuaGame] FPS %.1f (on-demand)\n", ctx->fps);
if(ctx->fps_label){
char buf[32];
snprintf(buf,sizeof(buf),"FPS %.0f",ctx->fps);
lv_label_set_text(ctx->fps_label, buf);
}
tt_lvgl_unlock();
ctx->fps_frames=0;
ctx->fps_last_us=now;
}
tt_lvgl_unlock();
} else {
printf("[LuaGame] lvgl lock timeout\n");
}
}
}
// For on-demand games, sleep longer to save CPU
@@ -739,7 +743,7 @@ static void game_loop_task(void* arg){
if(lua_pcall(L,0,0,0)!=LUA_OK){const char* e=lua_tostring(L,-1); printf("[LUA ERR draw] %s\n",e); lua_pop(L,1); ctx->lua_ok=false;}
}else lua_pop(L,1);
// Invalidate canvas with LVGL lock
if(tt_lvgl_lock(portMAX_DELAY)){
if(tt_lvgl_lock(pdMS_TO_TICKS(1000))){
invalidate_canvas(ctx);
// fps tracking inside lock for label update
ctx->fps_frames++;
@@ -872,9 +876,10 @@ static void app_on_show(AppHandle app,void* data,lv_obj_t* parent){
lv_obj_add_event_cb(cont,touch_event_cb,LV_EVENT_RELEASED,ctx);
lv_obj_add_event_cb(cont,touch_event_cb,LV_EVENT_PRESS_LOST,ctx);
printf("[LuaGame] spawning init task\n");
xTaskCreate(lua_init_task,"lua_init",16384,ctx,5,&ctx->lua_task);
fill_rect(ctx,0,0,GAME_W,GAME_H,hex_to_rgb565(0x1e1e2e),true);
if(tt_lvgl_lock(portMAX_DELAY)){
BaseType_t ret = xTaskCreate(lua_init_task,"lua_init",8192,ctx,5,&ctx->lua_task);
printf("[LuaGame] init task create ret=%d\n", ret);
fill_rect(ctx,0,0,ctx->fb_w,ctx->fb_h,hex_to_rgb565(0x1e1e2e),true);
if(tt_lvgl_lock(pdMS_TO_TICKS(1000))){
invalidate_canvas(ctx);
tt_lvgl_unlock();
}