Need help with segmentation fault in freetype library

Hello OCC community,

I have been experiencing a strange crash lately which originates from the freetype library. The application that is crashing is developed mainly on Windows platforms but time to time I compile it on my Ubuntu machine, as I work primarily in Ubuntu. I have recently updated to 13.10, but I am not sure if this update causes the problem I experience.

The situation:
when I start the application and initialize an OCC window (we use Qt for the GUI development), there is one point where the V3d_View::SetWindow function is called. After this, the application exits with a SIGSEGV signal. I could not figure out why, only that the crash happens in the freetype library.

Here is the valgrind output that I get (I compiled freetype and ftgl in debug mode, so that maybe a more detailed output can be seen):

==3510== Invalid read of size 8
==3510== at 0x13736BFA: ft_mem_qalloc (ftutil.c:76)
==3510== by 0x13736B95: ft_mem_alloc (ftutil.c:55)
==3510== by 0x13725D49: FT_Stream_New (ftobjs.c:171)
==3510== by 0x13728A78: FT_Open_Face (ftobjs.c:2059)
==3510== by 0x13727657: FT_New_Face (ftobjs.c:1254)
==3510== by 0x40F285C1: FTFace::FTFace(char const*, bool) (FTFace.cpp:44)
==3510== by 0x40F2E9E5: FTFontImpl::FTFontImpl(FTFont*, char const*) (FTFont.cpp:220)
==3510== by 0x40F322B8: FTTextureFontImpl::FTTextureFontImpl(FTFont*, char const*) (FTTextureFont.cpp:100)
==3510== by 0x40F32394: FTTextureFont::FTTextureFont(char const*) (FTTextureFont.cpp:46)
==3510== by 0x40A2C114: OpenGl_FontMgr::request_font(Handle_TCollection_HAsciiString const&, Font_FontAspect, int) (OpenGl_FontMgr.cxx:291)
==3510== by 0x40A29FB5: OpenGl_Display::FindFont(char const*, Font_FontAspect, int, float, float) (OpenGl_Display_1.cxx:191)
==3510== by 0x40A363A7: OpenGl_Workspace::FindFont(char const*, Font_FontAspect, int, float, float) (OpenGl_Workspace.hxx:176)
==3510== Address 0x1f0f2e66c3104793 is not stack'd, malloc'd or (recently) free'd
==3510==
==3510==
==3510== Process terminating with default action of signal 11 (SIGSEGV)
==3510== General Protection Fault
==3510== at 0x13736BFA: ft_mem_qalloc (ftutil.c:76)
==3510== by 0x13736B95: ft_mem_alloc (ftutil.c:55)
==3510== by 0x13725D49: FT_Stream_New (ftobjs.c:171)
==3510== by 0x13728A78: FT_Open_Face (ftobjs.c:2059)
==3510== by 0x13727657: FT_New_Face (ftobjs.c:1254)
==3510== by 0x40F285C1: FTFace::FTFace(char const*, bool) (FTFace.cpp:44)
==3510== by 0x40F2E9E5: FTFontImpl::FTFontImpl(FTFont*, char const*) (FTFont.cpp:220)
==3510== by 0x40F322B8: FTTextureFontImpl::FTTextureFontImpl(FTFont*, char const*) (FTTextureFont.cpp:100)
==3510== by 0x40F32394: FTTextureFont::FTTextureFont(char const*) (FTTextureFont.cpp:46)
==3510== by 0x40A2C114: OpenGl_FontMgr::request_font(Handle_TCollection_HAsciiString const&, Font_FontAspect, int) (OpenGl_FontMgr.cxx:291)
==3510== by 0x40A29FB5: OpenGl_Display::FindFont(char const*, Font_FontAspect, int, float, float) (OpenGl_Display_1.cxx:191)
==3510== by 0x40A363A7: OpenGl_Workspace::FindFont(char const*, Font_FontAspect, int, float, float) (OpenGl_Workspace.hxx:176)

The thing is that it used to work about a month ago, and nothing has changed in this part of the code, this is why I suspect that the problem is not in our code.

Do you have any guesses why it does not work?

Thanks
László

Laszlo Kudela's picture

Oh, by the way, I use OpenCASCADE 6.5.4 with Qt 4.8, and the Qt sample which is shipped with the OCC sources is working.

Laszlo Kudela's picture

Okay, I got it...

The problem was that in our framework we also link to the library "vtkftgl" provided by vtk, and the FTLibrary::Instance function was accidentaly linked to the wrong location. As OCC is calling this same function from the ftgl library, the two libraries were causing a conflict. Intersetingly, the linker was not complaining about this.