From d3fcd77a1ab94813effe2493862e6bc409576025 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 12 Jan 2024 08:21:03 -0800 Subject: [PATCH] guarantee font fallbacks if font loading fails --- src/df/gfx/df_gfx.c | 19 ++++++++++--------- src/raddbg/raddbg.cpp | 4 ---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index 3b115bfa..f75650d2 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -11205,13 +11205,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds) f_tag_from_static_data_string(&df_g_default_code_font_bytes), f_tag_from_static_data_string(&df_g_icon_font_bytes), }; - for(DF_FontSlot slot = (DF_FontSlot)0; slot < DF_FontSlot_COUNT; slot = (DF_FontSlot)(slot+1)) - { - if(f_tag_match(f_tag_zero(), df_gfx_state->cfg_font_tags[slot])) - { - df_gfx_state->cfg_font_tags[slot] = defaults[slot]; - } - } + MemoryZeroArray(df_gfx_state->cfg_font_tags); { DF_CfgVal *code_font_val = df_cfg_val_from_string(table, str8_lit("code_font")); DF_CfgVal *main_font_val = df_cfg_val_from_string(table, str8_lit("main_font")); @@ -11221,15 +11215,22 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds) String8 main_font_relative_path = main_font_cfg->first->string; String8 code_font_path = path_absolute_dst_from_relative_dst_src(scratch.arena, code_font_relative_path, cfg_folder); String8 main_font_path = path_absolute_dst_from_relative_dst_src(scratch.arena, main_font_relative_path, cfg_folder); - if(code_font_cfg != &df_g_nil_cfg_node && code_font_relative_path.size != 0) + if(os_file_path_exists(code_font_path) && code_font_cfg != &df_g_nil_cfg_node && code_font_relative_path.size != 0) { df_gfx_state->cfg_font_tags[DF_FontSlot_Code] = f_tag_from_path(code_font_path); } - if(main_font_cfg != &df_g_nil_cfg_node && main_font_relative_path.size != 0) + if(os_file_path_exists(main_font_path) && main_font_cfg != &df_g_nil_cfg_node && main_font_relative_path.size != 0) { df_gfx_state->cfg_font_tags[DF_FontSlot_Main] = f_tag_from_path(main_font_path); } } + for(DF_FontSlot slot = (DF_FontSlot)0; slot < DF_FontSlot_COUNT; slot = (DF_FontSlot)(slot+1)) + { + if(f_tag_match(f_tag_zero(), df_gfx_state->cfg_font_tags[slot])) + { + df_gfx_state->cfg_font_tags[slot] = defaults[slot]; + } + } } //- rjf: build windows & panel layouts diff --git a/src/raddbg/raddbg.cpp b/src/raddbg/raddbg.cpp index d641c563..fb7038a9 100644 --- a/src/raddbg/raddbg.cpp +++ b/src/raddbg/raddbg.cpp @@ -63,10 +63,6 @@ // Should probably make note that you have to set it to a path to a TTF, // since that's not normally how Windows fonts work. // -// [ ] Launching the debugger with an invalid code_font/main_font name doesn't -// have any fallback, so you just get no text at all. Probably should use -// a fallback font when font loading fails -// // [ ] disasm animation & go-to-address // // [ ] visualize mismatched source code and debug info