Skip to content

Commit 1a2cb12

Browse files
committed
Generate an error when trying to load a font with an invalid face, instead of defaulting to the last valid font face.
This optimizes `TextServerAdvanced::_ensure_cache_for_size`, improving editor startup times.
1 parent 3d9b05a commit 1a2cb12

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

modules/text_server_adv/text_server_adv.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,25 +1419,17 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
14191419
fargs.flags = FT_OPEN_MEMORY;
14201420
fargs.stream = &fd->stream;
14211421

1422-
int max_index = 0;
1423-
FT_Face tmp_face = nullptr;
1424-
error = FT_Open_Face(ft_library, &fargs, -1, &tmp_face);
1425-
if (tmp_face && error == 0) {
1426-
max_index = tmp_face->num_faces - 1;
1427-
}
1428-
if (tmp_face) {
1429-
FT_Done_Face(tmp_face);
1430-
}
1431-
1432-
error = FT_Open_Face(ft_library, &fargs, CLAMP(p_font_data->face_index, 0, max_index), &fd->face);
1422+
error = FT_Open_Face(ft_library, &fargs, p_font_data->face_index, &fd->face);
14331423
if (error) {
1434-
FT_Done_Face(fd->face);
1435-
fd->face = nullptr;
1424+
if (fd->face) {
1425+
FT_Done_Face(fd->face);
1426+
fd->face = nullptr;
1427+
}
14361428
memdelete(fd);
14371429
if (p_silent) {
14381430
return false;
14391431
} else {
1440-
ERR_FAIL_V_MSG(false, "FreeType: Error loading font: '" + String(FT_Error_String(error)) + "'.");
1432+
ERR_FAIL_V_MSG(false, "FreeType: Error loading font: '" + String(FT_Error_String(error)) + "' (face_index=" + String::num_int64(p_font_data->face_index) + ").");
14411433
}
14421434
}
14431435
}

0 commit comments

Comments
 (0)