I had the same problem. The crash was due to two places where you can get a NULL pointer: Glyph(charCode) and charMap->GlyphListIndex(charCode) returns 0 on errors, so using its result if 0 is not a good idea...
My fix was in FTGlyphContainer.cpp, my patch is
@@ -80,13 +80,21 @@
{
unsigned int index = charMap->GlyphListIndex(charCode);
+ // NOTE GlyphListIndex() returns 0 if not found.
+ // glyphs[0] is NULL, thus we save the test for those rare cases.
return (index < glyphs.size()) ? glyphs[index] : NULL;
}
If you provide a stack trace, that would help. You can get a trace by running FTGLDemo in gdb or another debugger and provoking the crash.
gdb --args demo/FTGLDemo
run
[make it crash]
backtrace
The back trace follows:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7979249 in find (c=<value optimized out>,
this=<value optimized out>) at FTCharToGlyphIndexMap.h:109
109 FTCharToGlyphIndexMap.h: Datei oder Verzeichnis nicht gefunden.
in FTCharToGlyphIndexMap.h
(gdb) bt
#0 0x00007ffff7979249 in find (c=<value optimized out>,
this=<value optimized out>) at FTCharToGlyphIndexMap.h:109
#1 FTCharmap::GlyphListIndex (c=<value optimized out>,
this=<value optimized out>) at FTCharmap.cpp:86
#2 0x00007ffff797c79d in FTGlyphContainer::Glyph (this=0x7eddf0, charCode=256)
at FTGlyphContainer.cpp:81
#3 0x00007ffff798356f in FTFontImpl::CheckGlyph (this=0x7c9810,
characterCode=256) at FTFont/FTFont.cpp:524
#4 0x00007ffff7984d89 in BBoxI<unsigned char> (spacing=<value optimized out>,
position=<value optimized out>, len=<value optimized out>,
string=<value optimized out>, this=<value optimized out>)
at FTFont/FTFont.cpp:391
#5 FTFontImpl::BBox (spacing=<value optimized out>,
position=<value optimized out>, len=<value optimized out>,
string=<value optimized out>, this=<value optimized out>)
at FTFont/FTFont.cpp:427
#6 0x00007ffff7983483 in FTFont::BBox (this=<value optimized out>,
string=0x7f92d1 "", len=8360657, position=..., spacing=...)
at FTFont/FTFont.cpp:193
#7 0x00007ffff798ccc9 in WrapTextI<char> (bounds=<value optimized out>,
renderMode=<value optimized out>, position=..., len=<value optimized out>,
buf=<value optimized out>, this=<value optimized out>)
at FTLayout/FTSimpleLayout.cpp:223
---Type <return> to continue, or q <return> to quit---
#8 FTSimpleLayoutImpl::WrapText (bounds=<value optimized out>,
renderMode=<value optimized out>, position=..., len=<value optimized out>,
buf=<value optimized out>, this=<value optimized out>)
at FTLayout/FTSimpleLayout.cpp:322
#9 0x0000000000404d46 in do_display () at FTGLDemo.cpp:427
#10 0x00000000004050a3 in display () at FTGLDemo.cpp:477
#11 0x00007ffff7bb92ed in ?? () from /usr/lib64/libglut.so.3
#12 0x00007ffff7bbcb99 in fgEnumWindows () from /usr/lib64/libglut.so.3
#13 0x00007ffff7bb97b2 in glutMainLoopEvent () from /usr/lib64/libglut.so.3
#14 0x00007ffff7bba107 in glutMainLoop () from /usr/lib64/libglut.so.3
#15 0x0000000000405d77 in main (argc=1, argv=0x7fffffffd9b8)
at FTGLDemo.cpp:738
(gdb)
To fix that in y application I used the wchar_t interface.
http://www.oyranos.org/scm?p=icc_examin.git;a=commitdiff;h=d7e35b93e54c0dd6f1e02e048bd9ae12f6bc977b
with roughly:
#define ZeichneText(Font, Zeiger) Font->Render(Zeiger);
So it could as well be regarded as a feature request to switch to wchar_t for the demo.
Thanks for the stack trace! The demo can be changed, but the library still shouldn't crash.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
I had the same problem. The crash was due to two places where you can get a NULL pointer: Glyph(charCode) and charMap->GlyphListIndex(charCode) returns 0 on errors, so using its result if 0 is not a good idea...
My fix was in FTGlyphContainer.cpp, my patch is
@@ -80,13 +80,21 @@
{
unsigned int index = charMap->GlyphListIndex(charCode);
+ // NOTE GlyphListIndex() returns 0 if not found.
+ // glyphs[0] is NULL, thus we save the test for those rare cases.
return (index < glyphs.size()) ? glyphs[index] : NULL;
}
FTBBox FTGlyphContainer::BBox(const unsigned int charCode) const
{
- return Glyph(charCode)->BBox();
+ const FTGlyph *glyph = Glyph(charCode);
+
+ if (!glyph)
+ {
+ return FTBBox();
+ }
+ return glyph->BBox();
}
and in FTPoint FTGlyphContainer::Render:
@@ -116,7 +124,7 @@
if(!face->Error())
{
unsigned int index = charMap->GlyphListIndex(charCode);
- if (index < glyphs.size())
+ if (index < glyphs.size() && index != 0)
kernAdvance += glyphs[index]->Render(penPosition, renderMode);
}
Last edit: Anonymous 2018-10-12