I am using cairo on MinGW-w64, Windows 10. The following code produces a crash: #include <ft2build.h> #include <cairo/cairo.h> #include <cairo/cairo-ft.h> int main(){ FT_Library ft; FT_Face textFont; cairo_font_face_t *cairoFont; FT_Init_FreeType(&ft); FT_New_Face(ft,"Hack-Regular.ttf",0,&textFont); cairoFont = cairo_ft_font_face_create_for_ft_face(textFont,0); // This line produces segmentation fault return 0; } The problem seems to be that EnterCriticalSection is called before InitializeCriticalSection. A quick workaround is to initialize it manually: #include <ft2build.h> #include <cairo/cairo.h> #include <cairo/cairo-ft.h> extern "C" void _cairo_mutex_initialize(); int main(){ FT_Library ft; FT_Face textFont; cairo_font_face_t *cairoFont; FT_Init_FreeType(&ft); FT_New_Face(ft,"Hack-Regular.ttf",0,&textFont); _cairo_mutex_initialize(); //This eliminates the segfault cairoFont = cairo_ft_font_face_create_for_ft_face(textFont,0); return 0; }
From a quick look at the code: Adding CAIRO_MUTEX_INITIALIZE(); to _cairo_ft_unscaled_font_map_lock() should do the trick, but I'm not sure this is the right place to do this. I picked this place since (a) this is where the mutex is actually locked for the first time (b) cairo_ft_font_face_create_for_ft_face() pretty much directly calls this function before doing anything (well, through some indirection) (Sorry, I neither have time to test the above nor can I commit it currently)
This bugs occurs only when cairo is linked statically. Apparently this is because _cairo_mutex_initialize() is called during DllMain, but not when cairo is statically linked. There should be some manual way to initialize cairo. Also I found this related bug: https://lists.cairographics.org/archives/cairo/2017-June/028131.html
-- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/312.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.