Skip to content

Commit

Permalink
Merge pull request #2944 from pygame/ftfont-crash
Browse files Browse the repository at this point in the history
freetype: Fix intermittent crash with test_font_file_not_found
  • Loading branch information
illume committed Dec 24, 2021
2 parents 4d96a95 + 8401952 commit 8497b4e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src_c/freetype/ft_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,20 @@ _PGFT_TryLoadFont_Filename(FreeTypeInstance *ft, pgFontObject *fontobj,
char *filename_alloc;
size_t file_len;

/* There seems to be an intermittent crash with opening
a missing file and freetype 2.11.1 on mac homebrew.
python3 test/ftfont_test.py -k test_font_file_not_found
So instead we look for a missing file with SDL_RWFromFile first.
*/
SDL_RWops *sdlfile = SDL_RWFromFile(filename, "rb");
if (!sdlfile) {
PyErr_Format(PyExc_FileNotFoundError,
"No such file or directory: '%s'.", filename);
return -1;
}
SDL_RWclose(sdlfile);

file_len = strlen(filename);
filename_alloc = _PGFT_malloc(file_len + 1);
if (!filename_alloc) {
Expand Down

0 comments on commit 8497b4e

Please sign in to comment.