Fix: Handle Missing Font in ID List Previews

Handle missing font in the hover tooltip preview in the Data-block ID
selector. Add error handing both in IMB_font_preview itself and in the
current caller (to show message).

Pull Request: https://projects.blender.org/blender/blender/pulls/124111
This commit is contained in:
Harley Acheson 2024-07-03 18:24:28 +02:00 committed by Harley Acheson
parent 5b50bb19e7
commit c6411e61ae
2 changed files with 10 additions and 0 deletions

@ -28,6 +28,7 @@
#include "DNA_userdef_types.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_math_color.h"
#include "BLI_math_vector.h"
@ -1724,6 +1725,12 @@ static void ui_tooltip_from_vfont(VFont &font, uiTooltipData &data)
return;
}
if (!BLI_exists(font.filepath)) {
UI_tooltip_text_field_add(
&data, TIP_("File not found"), {}, UI_TIP_STYLE_NORMAL, UI_TIP_LC_ALERT);
return;
}
float color[4];
const uiWidgetColors *theme = ui_tooltip_get_theme();
rgba_uchar_to_float(color, theme->text);

@ -49,6 +49,9 @@ bool IMB_thumb_load_font_get_hash(char *r_hash)
ImBuf *IMB_font_preview(const char *filepath, uint width, const float color[4])
{
int font_id = (filepath[0] != '<') ? BLF_load(filepath) : 0;
if (font_id == -1) {
return nullptr;
}
const char sample[] = "ABCDEFGH\nabcdefg123";
BLF_buffer_col(font_id, color);