From d8244120e964dc6d0e95b67aad78f6376d29ee7f Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 5 May 2021 09:32:24 +0200 Subject: [PATCH] Ensure the rencache commands buffer is cleared on restart Fix issue #176 but it should be tested more thoroughly. --- src/main.c | 6 ++++++ src/rencache.c | 4 ++++ src/rencache.h | 1 + 3 files changed, 11 insertions(+) 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