FT_New_Face returns error 1 (Cannot_Open_Resource) when filepath is a variable, but not a hard-coded string

1.3k Views Asked by At

The following code produces error 1:

  FT_Library library;
  int error = FT_Init_FreeType(&library);
  if (error) handleError("Problem initing freetype");

  FT_Face face;
  const char* filename = "fonts/regular.tff";
  error = FT_New_Face(library, filename, 0, &face);
  if (error == FT_Err_Unknown_File_Format) {
    handleError("Unknown font file format %s", filename);
    return;
  } else if (error) {
    handleError("Error %d loading font %s", error, filename);
    return;
  }

However, one line change makes it work:

  error = FT_New_Face(library, "fonts/regular.tff", 0, &face);

I'm being forced to hardcode the font file, but I want to be able change it at runtime. I can't figure out why a constant variable would have a different result than hardcoding.

0

There are 0 best solutions below