diff --git a/src/main.c b/src/main.c index 43652fbc..ca332dd6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include #include #include "api/api.h" +#include "rencache.h" #include "renderer.h" #ifdef _WIN32 @@ -158,6 +159,11 @@ init_lua: enable_momentum_scroll(); #endif + /* We need to clear the rencache commands because we may restarting the application + and it could be non-empty. It is important to clear the command buffer because it + stores pointers to font_desc objects and these are Lua managed. */ + rencache_clear(); + const char *init_lite_code = \ "local core\n" "xpcall(function()\n" diff --git a/src/rencache.c b/src/rencache.c index 36734b24..1f3e42c2 100644 --- a/src/rencache.c +++ b/src/rencache.c @@ -312,3 +312,7 @@ void rencache_end_frame(void) { cells_prev = tmp; command_buf_idx = 0; } + +void rencache_clear() { + command_buf_idx = 0; +} diff --git a/src/rencache.h b/src/rencache.h index b5c241ab..987b6855 100644 --- a/src/rencache.h +++ b/src/rencache.h @@ -13,5 +13,6 @@ int rencache_draw_text(FontDesc *font_desc, const char *text, int x, int y, Ren void rencache_invalidate(void); void rencache_begin_frame(void); void rencache_end_frame(void); +void rencache_clear(); #endif