<html>
<head>
<base href="https://bugs.freedesktop.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - cairo_ft_font_face_create_for_ft_face causes segmentation fault"
href="https://bugs.freedesktop.org/show_bug.cgi?id=106967">106967</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>cairo_ft_font_face_create_for_ft_face causes segmentation fault
</td>
</tr>
<tr>
<th>Product</th>
<td>cairo
</td>
</tr>
<tr>
<th>Version</th>
<td>1.12.14
</td>
</tr>
<tr>
<th>Hardware</th>
<td>x86-64 (AMD64)
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows (All)
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>medium
</td>
</tr>
<tr>
<th>Component</th>
<td>freetype font backend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>david@freetype.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>longfeiqiu2012@gmail.com
</td>
</tr>
<tr>
<th>QA Contact</th>
<td>cairo-bugs@cairographics.org
</td>
</tr></table>
<p>
<div>
<pre>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;
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the QA Contact for the bug.</li>
</ul>
</body>
</html>