diff -r 9c44c55d327a -r 8297afa1c29c src/context.c --- a/src/context.c Thu Apr 18 22:53:55 2024 +0200 +++ b/src/context.c Fri Apr 19 22:28:29 2024 +0200 @@ -42,14 +42,24 @@ return 1000000000ull*(uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec; } +// forward declare non-public font cache functions +void asc_font_cache_init(void); +void asc_font_cache_destroy(void); + void asc_context_initialize(void) { if (asc_test_flag(asc_context.flags, ASC_FLAG_INITILIZED)) return; memset(&asc_context, 0, sizeof(AscContext)); - // nothing is active right after initialization + // initialize the font cache + asc_font_cache_init(); + + // set a default font, but do not load it + asc_context.active_font.style = ASC_FONT_REGULAR; + asc_context.active_font.size = 14; + + // no window, yet asc_context.active_window = ASC_MAX_WINDOWS; - asc_context.active_font = ASC_MAX_FONTS; // initialize error buffer cxBufferInit( @@ -75,10 +85,13 @@ } void asc_context_destroy(void) { + // destroy windows for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) { asc_window_destroy(i); } - // TODO: fix that fonts are currently leaking by reworking the font cache + + // destroy the font cache + asc_font_cache_destroy(); // quit SDL if (TTF_WasInit()) @@ -95,6 +108,15 @@ asc_set_flag(asc_context.flags, ASC_FLAG_QUIT); } +AscWindow *asc_active_window_assert() { + if (asc_context.active_window < ASC_MAX_WINDOWS) { + return &asc_context.windows[asc_context.active_window]; + } else { + asc_dprintf("Window access attempted without active window"); + abort(); + } +} + static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) { for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) { if (asc_context.windows[i].id == id) {