Fix crash problem with rencache and font access
In some cases rencache was using a FontDesc pointer that was actually freed by Lua giving segfaults errors. In addition, some FontDesc object were not freed in some cases if the rencache_end_frame was not called when performing the "restart" command. The invalid access problem can happen because rencache keep some pointers to FontDesc object but these are Lua userdata that Lua can dispose of. This situation is prone to hard errors and we should avoid to keep pointers to objects managed by Lua. To this purpose we use luaL_ref/unref to bind the FontDesc into the Lua's registry while rencache need them. We still keeps pointer to FontDesc object but using luaL_ref we are assured they will not be disposed by Lua. Since we are using luaL_ref/unref to inform the GC about when the objects are in use we can now finalize the objects directly when Lua collects them. Previously the GC metamethods was issuing a FREE command to rencache and the font was actually freed only from the rencache_end_frame function.
This commit is contained in:
+4
-5
@@ -2,17 +2,16 @@
|
||||
#define RENCACHE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <lua.h>
|
||||
#include "renderer.h"
|
||||
|
||||
void rencache_show_debug(bool enable);
|
||||
void rencache_free_font(FontDesc *font_desc);
|
||||
void rencache_set_clip_rect(RenRect rect);
|
||||
void rencache_draw_rect(RenRect rect, RenColor color);
|
||||
int rencache_draw_text(FontDesc *font_desc, const char *text, int x, int y, RenColor color,
|
||||
int rencache_draw_text(lua_State *L, FontDesc *font_desc, int font_index, const char *text, int x, int y, RenColor color,
|
||||
bool draw_subpixel, CPReplaceTable *replacements, RenColor replace_color);
|
||||
void rencache_invalidate(void);
|
||||
void rencache_begin_frame(void);
|
||||
void rencache_end_frame(void);
|
||||
void rencache_clear();
|
||||
void rencache_begin_frame(lua_State *L);
|
||||
void rencache_end_frame(lua_State *L);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user