[vtkusers] vtkFreeType in a multi-threading application

Butterfly ninarock at list.ru
Wed Mar 11 08:26:02 EDT 2015


Hi, I've read that much work was done lately for thread safety in VTK, and
I'am very happy about this, but unfortunately I have a problem while trying
it in my example. I tried this in VTK 6.1 and VTK 6.2 under Windows 32 bit.

In my application I initiate two threads (for simplicity let's say I don't
need any communication, they are completely independent). Each thread
creates its own vtkChartXY, data in the chart is continuously updated, e.g.
10 times per second. 

After start both render windows show normally, I see the data update in both
windows several times (about 10 times or more..) and then the application
crashes with "corruption of the heap" error "HEAP: Free Heap block 12e58b20
modified at 12e58b78 after it was freed". The call stack is not the same at
each start, but the error is always inside the vtkFreeType.dll (please see 2
examples of the call stack below).

As I understand the error appears while drawing text in the chart (drawing
axis labels and chart legend). I tried to read about FreeType project, and I
found the following:
*    For multi-threading applications each thread should have its own
FT_Library object.* 
http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html
<http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html>  

But if I understand right, VTK creates only one instance of vtkFreeTypeTools
(in the code is said that it is a singleton), and consequently we have only
one FT_Library object.

I understand that charts does not require much computation power and we can
let them all live in one thread, but this problem may occur also for 3D
render windows where we use axes actors that also render text.

Is there any solution for my problem? Are there any plans for future
releases that address this issue?

Many thanks in advance!

Call stack example 1:

msvcr110d.dll!_heap_alloc_base(unsigned int size)  Line 57
msvcr110d.dll!_heap_alloc_dbg_impl(unsigned int nSize, int nBlockUse, const
char * szFileName, int nLine, int * errno_tmp)  Line 431 + 0x9 bytes
msvcr110d.dll!_nh_malloc_dbg_impl(unsigned int nSize, int nhFlag, int
nBlockUse, const char * szFileName, int nLine, int * errno_tmp)  Line 239 +
0x19 bytes
msvcr110d.dll!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int nBlockUse,
const char * szFileName, int nLine)  Line 302 + 0x1d bytes
msvcr110d.dll!malloc(unsigned int nSize)  Line 56 + 0x15 bytes
vtkfreetype-6.2.dll!ft_alloc(FT_MemoryRec_ * memory, long size)  Line 74 +
0xc bytes
vtkfreetype-6.2.dll!vtk_freetype_ft_mem_qalloc(FT_MemoryRec_ * memory, long
size, int * p_error)  Line 76 + 0x12 bytes
vtkfreetype-6.2.dll!vtk_freetype_ft_mem_alloc(FT_MemoryRec_ * memory, long
size, int * p_error)  Line 55 + 0x11 bytes
vtkfreetype-6.2.dll!ft_smooth_render_generic(FT_RendererRec_ * render,
FT_GlyphSlotRec_ * slot, FT_Render_Mode_ mode, const FT_Vector_ * origin,
FT_Render_Mode_ required_mode)  Line 244 + 0x15 bytes
vtkfreetype-6.2.dll!ft_smooth_render(FT_RendererRec_ * render,
FT_GlyphSlotRec_ * slot, FT_Render_Mode_ mode, const FT_Vector_ * origin) 
Line 384 + 0x17 bytes
vtkfreetype-6.2.dll!vtk_freetype_FT_Render_Glyph_Internal(FT_LibraryRec_ *
library, FT_GlyphSlotRec_ * slot, FT_Render_Mode_ render_mode)  Line 4021 +
0x18 bytes
vtkfreetype-6.2.dll!vtk_freetype_FT_Render_Glyph(FT_GlyphSlotRec_ * slot,
FT_Render_Mode_ render_mode)  Line 4061 + 0x11 bytes
vtkfreetype-6.2.dll!vtk_freetype_FT_Load_Glyph(FT_FaceRec_ * face, unsigned
int glyph_index, int load_flags)  Line 794 + 0xd bytes
vtkfreetype-6.2.dll!ftc_basic_family_load_glyph(FTC_FamilyRec_ * ftcfamily,
unsigned int gindex, FTC_CacheRec_ * cache, FT_GlyphRec_ * * aglyph)  Line
211 + 0x14 bytes
vtkfreetype-6.2.dll!FTC_INode_New(FTC_INodeRec_ * * pinode, FTC_GQueryRec_ *
gquery, FTC_CacheRec_ * cache)  Line 80 + 0x1d bytes
vtkfreetype-6.2.dll!ftc_inode_new(FTC_NodeRec_ * * ftcpinode, void *
ftcgquery, FTC_CacheRec_ * cache)  Line 102 + 0x11 bytes
vtkfreetype-6.2.dll!FTC_Cache_NewNode(FTC_CacheRec_ * cache, int hash, void
* query, FTC_NodeRec_ * * anode)  Line 466 + 0x16 bytes
vtkfreetype-6.2.dll!vtk_freetype_FTC_ImageCache_Lookup(FTC_ImageCacheRec_ *
cache, FTC_ImageTypeRec_ * type, unsigned int gindex, FT_GlyphRec_ * *
aglyph, FTC_NodeRec_ * * anode)  Line 385 + 0x2ae bytes
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::GetGlyph(unsigned long
tprop_cache_id, int font_size, unsigned int gindex, FT_GlyphRec_ * * glyph,
int request)  Line 867 + 0x1c bytes
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::GetBitmap(unsigned int c,
unsigned long prop_cache_id, int prop_font_size, unsigned int & gindex,
FT_BitmapGlyphRec_ * & bitmap_glyph)  Line 2230 + 0x1c bytes
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::GetLineMetrics<vtkUnicodeString::const_iterator>(vtkUnicodeString::const_iterator
begin, vtkUnicodeString::const_iterator end, vtkFreeTypeTools::MetaData &
metaData, int & width, int * bbox)  Line 2324 + 0x2e bytes
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::CalculateBoundingBox<vtkUnicodeString>(const
vtkUnicodeString & str, vtkFreeTypeTools::MetaData & metaData)  Line 1273
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::GetBoundingBox(vtkTextProperty
* tprop, const vtkUnicodeString & str, int * bbox)  Line 447 + 0x13 bytes
vtkRenderingFreeType-6.2.dll!vtkMathTextFreeTypeTextRenderer::GetBoundingBoxInternal(vtkTextProperty
* tprop, const vtkUnicodeString & str, int * bbox, int dpi, int backend) 
Line 155 + 0x1d bytes
vtkRenderingCore-6.2.dll!vtkTextRenderer::GetBoundingBox(vtkTextProperty *
tprop, const vtkUnicodeString & str, int * bbox, int dpi, int backend)  Line
160 + 0x23 bytes
vtkRenderingFreeType-6.2.dll!vtkTextRendererStringToImage::GetBounds(vtkTextProperty
* property, const vtkUnicodeString & string)  Line 62 + 0x23 bytes
vtkRenderingContextOpenGL-6.2.dll!vtkOpenGLContextDevice2D::ComputeStringBounds(const
vtkUnicodeString & string, float * bounds)  Line 889 + 0x2d bytes
vtkRenderingContextOpenGL-6.2.dll!vtkOpenGLContextDevice2D::ComputeStringBounds(const
vtkStdString & string, float * bounds)  Line 812 + 0x41 bytes
vtkRenderingContext2D-6.2.dll!vtkContext2D::ComputeStringBounds(const
vtkStdString & string, float * bounds)  Line 619 + 0x23 bytes
vtkChartsCore-6.2.dll!vtkAxis::GetBoundingRect(vtkContext2D * painter)  Line
875 + 0x38 bytes
vtkChartsCore-6.2.dll!vtkChartXY::UpdateLayout(vtkContext2D * painter)  Line
845
vtkChartsCore-6.2.dll!vtkChartXY::Paint(vtkContext2D * painter)  Line 405 +
0x16 bytes
vtkRenderingContext2D-6.2.dll!vtkContextScenePrivate::PaintItems(vtkContext2D
* context)  Line 80 + 0x20 bytes
vtkRenderingContext2D-6.2.dll!vtkContextScene::Paint(vtkContext2D * painter) 
Line 120
vtkRenderingContext2D-6.2.dll!vtkContextActor::RenderOverlay(vtkViewport *
viewport)  Line 220 + 0x38 bytes
vtkRenderingCore-6.2.dll!vtkRenderer::UpdateGeometry()  Line 584 + 0x2e
bytes
vtkRenderingOpenGL-6.2.dll!vtkOpenGLRenderer::DeviceRender()  Line 270 +
0x12 bytes
vtkRenderingCore-6.2.dll!vtkRenderer::Render()  Line 291 + 0x12 bytes
vtkRenderingCore-6.2.dll!vtkRendererCollection::Render()  Line 51 + 0x12
bytes
vtkRenderingCore-6.2.dll!vtkRenderWindow::DoStereoRender()  Line 774
vtkRenderingCore-6.2.dll!vtkRenderWindow::DoFDRender()  Line 740 + 0x12
bytes
vtkRenderingCore-6.2.dll!vtkRenderWindow::DoAARender()  Line 619 + 0x12
bytes
vtkRenderingCore-6.2.dll!vtkRenderWindow::Render()  Line 435 + 0x12 bytes

Call stack example 2:

vtkfreetype-6.2.dll!gray_find_cell(TWorker_ * worker)  Line 470 + 0x5 bytes
vtkfreetype-6.2.dll!gray_record_cell(TWorker_ * worker)  Line 501 + 0x9
bytes
vtkfreetype-6.2.dll!gray_set_cell(TWorker_ * worker, long ex, long ey)  Line
544 + 0x9 bytes
vtkfreetype-6.2.dll!gray_render_line(TWorker_ * worker, long to_x, long
to_y)  Line 835 + 0x14 bytes
vtkfreetype-6.2.dll!gray_line_to(const FT_Vector_ * to, TWorker_ * worker) 
Line 1136 + 0x1c bytes
vtkfreetype-6.2.dll!vtk_freetype_FT_Outline_Decompose(FT_Outline_ * outline,
const FT_Outline_Funcs_ * func_interface, void * user)  Line 160 + 0x12
bytes
vtkfreetype-6.2.dll!gray_convert_glyph_inner(TWorker_ * worker)  Line 1706 +
0x18 bytes
vtkfreetype-6.2.dll!gray_convert_glyph(TWorker_ * worker)  Line 1808 + 0x9
bytes
vtkfreetype-6.2.dll!gray_raster_render(TRaster_ * raster, const
FT_Raster_Params_ * params)  Line 1938 + 0x9 bytes
vtkfreetype-6.2.dll!ft_smooth_render_generic(FT_RendererRec_ * render,
FT_GlyphSlotRec_ * slot, FT_Render_Mode_ mode, const FT_Vector_ * origin,
FT_Render_Mode_ required_mode)  Line 297 + 0x18 bytes
vtkfreetype-6.2.dll!ft_smooth_render(FT_RendererRec_ * render,
FT_GlyphSlotRec_ * slot, FT_Render_Mode_ mode, const FT_Vector_ * origin) 
Line 384 + 0x17 bytes
vtkfreetype-6.2.dll!vtk_freetype_FT_Render_Glyph_Internal(FT_LibraryRec_ *
library, FT_GlyphSlotRec_ * slot, FT_Render_Mode_ render_mode)  Line 4021 +
0x18 bytes
vtkfreetype-6.2.dll!vtk_freetype_FT_Render_Glyph(FT_GlyphSlotRec_ * slot,
FT_Render_Mode_ render_mode)  Line 4061 + 0x11 bytes
vtkfreetype-6.2.dll!vtk_freetype_FT_Load_Glyph(FT_FaceRec_ * face, unsigned
int glyph_index, int load_flags)  Line 794 + 0xd bytes
vtkfreetype-6.2.dll!ftc_basic_family_load_glyph(FTC_FamilyRec_ * ftcfamily,
unsigned int gindex, FTC_CacheRec_ * cache, FT_GlyphRec_ * * aglyph)  Line
211 + 0x14 bytes
vtkfreetype-6.2.dll!FTC_INode_New(FTC_INodeRec_ * * pinode, FTC_GQueryRec_ *
gquery, FTC_CacheRec_ * cache)  Line 80 + 0x1d bytes
vtkfreetype-6.2.dll!ftc_inode_new(FTC_NodeRec_ * * ftcpinode, void *
ftcgquery, FTC_CacheRec_ * cache)  Line 102 + 0x11 bytes
vtkfreetype-6.2.dll!FTC_Cache_NewNode(FTC_CacheRec_ * cache, int hash, void
* query, FTC_NodeRec_ * * anode)  Line 466 + 0x16 bytes
vtkfreetype-6.2.dll!vtk_freetype_FTC_ImageCache_Lookup(FTC_ImageCacheRec_ *
cache, FTC_ImageTypeRec_ * type, unsigned int gindex, FT_GlyphRec_ * *
aglyph, FTC_NodeRec_ * * anode)  Line 385 + 0x2ae bytes
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::GetGlyph(unsigned long
tprop_cache_id, int font_size, unsigned int gindex, FT_GlyphRec_ * * glyph,
int request)  Line 867 + 0x1c bytes
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::GetBitmap(unsigned int c,
unsigned long prop_cache_id, int prop_font_size, unsigned int & gindex,
FT_BitmapGlyphRec_ * & bitmap_glyph)  Line 2230 + 0x1c bytes
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::CalculateBoundingBox<vtkUnicodeString>(const
vtkUnicodeString & str, vtkFreeTypeTools::MetaData & metaData)  Line 1289 +
0x28 bytes
vtkRenderingFreeType-6.2.dll!vtkFreeTypeTools::GetBoundingBox(vtkTextProperty
* tprop, const vtkUnicodeString & str, int * bbox)  Line 447 + 0x13 bytes
vtkRenderingFreeType-6.2.dll!vtkMathTextFreeTypeTextRenderer::GetBoundingBoxInternal(vtkTextProperty
* tprop, const vtkUnicodeString & str, int * bbox, int dpi, int backend) 
Line 155 + 0x1d bytes
vtkRenderingCore-6.2.dll!vtkTextRenderer::GetBoundingBox(vtkTextProperty *
tprop, const vtkUnicodeString & str, int * bbox, int dpi, int backend)  Line
160 + 0x23 bytes
vtkRenderingFreeType-6.2.dll!vtkTextRendererStringToImage::GetBounds(vtkTextProperty
* property, const vtkUnicodeString & string)  Line 62 + 0x23 bytes
vtkRenderingContextOpenGL-6.2.dll!vtkOpenGLContextDevice2D::ComputeStringBounds(const
vtkUnicodeString & string, float * bounds)  Line 889 + 0x2d bytes
vtkRenderingContextOpenGL-6.2.dll!vtkOpenGLContextDevice2D::ComputeStringBounds(const
vtkStdString & string, float * bounds)  Line 812 + 0x41 bytes
vtkRenderingContext2D-6.2.dll!vtkContext2D::ComputeStringBounds(const
vtkStdString & string, float * bounds)  Line 619 + 0x23 bytes
vtkChartsCore-6.2.dll!vtkAxis::GetBoundingRect(vtkContext2D * painter)  Line
875 + 0x38 bytes
vtkChartsCore-6.2.dll!vtkAxis::Paint(vtkContext2D * painter)  Line 297
vtkRenderingContext2D-6.2.dll!vtkContextScenePrivate::PaintItems(vtkContext2D
* context)  Line 80 + 0x20 bytes
vtkRenderingContext2D-6.2.dll!vtkAbstractContextItem::PaintChildren(vtkContext2D
* painter)  Line 51
vtkChartsCore-6.2.dll!vtkChartXY::Paint(vtkContext2D * painter)  Line 425 +
0x13 bytes
vtkRenderingContext2D-6.2.dll!vtkContextScenePrivate::PaintItems(vtkContext2D
* context)  Line 80 + 0x20 bytes
vtkRenderingContext2D-6.2.dll!vtkContextScene::Paint(vtkContext2D * painter) 
Line 120
vtkRenderingContext2D-6.2.dll!vtkContextActor::RenderOverlay(vtkViewport *
viewport)  Line 220 + 0x38 bytes
vtkRenderingCore-6.2.dll!vtkRenderer::UpdateGeometry()  Line 584 + 0x2e
bytes
vtkRenderingOpenGL-6.2.dll!vtkOpenGLRenderer::DeviceRender()  Line 270 +
0x12 bytes
vtkRenderingCore-6.2.dll!vtkRenderer::Render()  Line 291 + 0x12 bytes
vtkRenderingCore-6.2.dll!vtkRendererCollection::Render()  Line 51 + 0x12
bytes
vtkRenderingCore-6.2.dll!vtkRenderWindow::DoStereoRender()  Line 774
vtkRenderingCore-6.2.dll!vtkRenderWindow::DoFDRender()  Line 740 + 0x12
bytes
vtkRenderingCore-6.2.dll!vtkRenderWindow::DoAARender()  Line 619 + 0x12
bytes
vtkRenderingCore-6.2.dll!vtkRenderWindow::Render()  Line 435 + 0x12 bytes



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkFreeType-in-a-multi-threading-application-tp5730743.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list