Hi all,
I have a couple of issues/questions about the osg plugin for svg file format.
1.
I got win32 prebuilt versions of the library librsvg, and all required dependencies (glib, gdk-pixbuf, cairo, libcroco, fontconfig, libpng, freetype, gettext-runtime, libxml2, expat, pango), from this website:
http://ftp.acc.umu.se/pub/gnome/binaries/win32.
And rebuilt the osgdb_svg.dll plugin (in OSG 3.0.1).
When I try to read an svg image in my application, I have a crash in the yellow line in following function inside ReaderWriterSVG.cpp:
osg::Image* createImage(RsvgHandle *handle, unsigned int width, unsigned int height) const
{
RsvgDimensionData dimensionData;
rsvg_handle_get_dimensions( handle, &dimensionData);
// If image resollution < 128, cairo produces some artifacts.
// I don't know why, but we check the size...
if (width < 128) width = 128;
if (height < 128) height = 128;
width = osg::Image::computeNearestPowerOfTwo(width);
height = osg::Image::computeNearestPowerOfTwo(height);
osg::Image *image = new osg::Image();
image->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
image->setPixelFormat(GL_BGRA);
cairo_surface_t *cairo_surface = cairo_image_surface_create_for_data(image->data(),
CAIRO_FORMAT_ARGB32, width, height, image->getRowSizeInBytes());
cairo_t *cr = cairo_create(cairo_surface);
cairo_scale(cr,((float)width)/dimensionData.width, ((float)height)/dimensionData.height);
rsvg_handle_render_cairo(handle, cr);
cairo_destroy(cr);
free(cairo_surface);
image->flipVertical();
return image;
}
It looks like a memory corruption. Any idea about what might be wrong?
Could anyone of you build and use the svg plugin successfully? If yes, where did you get the librsvg library? What version? What versions for required dependencies?
2.
I looked into ReaderWriterSVG.cpp, and saw that the plugin can read an svg as an image. Since the svg is a vector file format, isn’t there a way in OSG to directly construct a scene graph from that file, returning for example the root node of that scene graph? Also, I saw that there is no ‘writeImage’ implementation. Is there any way to write an svg file, starting from a scene graph (i.e. passing the root node of such a graph)? Or can it only manage the svg files as raster images?
Thanks
Gianluca
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Thanks Robert,
I’ll try with different versions of libraries and different .svg test files, to see if the crash disappears.
Gianluca
Da: osg-user...@lists.openscenegraph.org [mailto:osg-user...@lists.openscenegraph.org]
Per conto di Robert Osfield
Inviato: giovedì 13 dicembre 2012 15:51
A: OpenSceneGraph Users
Oggetto: Re: [osg-users] a couple of questions about svg plugin (OSG 3.0.1)
Unfortunately it crashed with any version of cairo library (gotten from http://ftp.acc.umu.se/pub/gnome/binaries/win32), and any .svg file I tested.
I ended up looking deeper at documentation of cairo library.
Specifically, since the crash happened (as shown here below in yellow) when it tries to free the memory allocated for a cairo_surface_t,
I looked at cairo.h, and found this comment:
* Memory management of #cairo_surface_t is done with
* cairo_surface_reference() and cairo_surface_destroy().
So, I tried to replace the call (at yellow line here below):
free(cairo_surface);
with a:
cairo_surface_destroy(cairo_surface);
I rebuilt osgdb_svg.dll, and now it seems to work. I can load any .svg file and use as a texture with no crash.
But I still wonder if that replacement really deallocates the memory allocated for the cairo surface.
Anyway, it seems quite strange to me that the svg plugin could work without crashes for all of you who tried it (on Win32), without the hack that I had to do,
since the hack is actually in osg and not in third party libraries.
So, again, I would appreciate if any of you who successfully built and used the osg svg plugin as it was, i.e. without my replacement,
could let me know where he got the required libraries for svg.
BTW, I built OSG 3.0.1 in win32 debug, with VisualStudio 2010 on Win7.
Thanks,
Gianluca
Da: osg-user...@lists.openscenegraph.org [mailto:osg-user...@lists.openscenegraph.org]
Per conto di
Gianluca Natale
Inviato: giovedì 13 dicembre 2012 16:02
A: OpenSceneGraph Users
Oggetto: [osg-users] R: a couple of questions about svg plugin (OSG 3.0.1)
Unfortunately it crashed with any version of cairo library (gotten from http://ftp.acc.umu.se/pub/gnome/binaries/win32), and any .svg file I tested.
I ended up looking deeper at documentation of cairo library.
Specifically, since the crash happened (as shown here below in yellow) when it tries to free the memory allocated for a cairo_surface_t,
I looked at cairo.h, and found this comment:
�
* Memory management of #cairo_surface_t is done with
* cairo_surface_reference() and cairo_surface_destroy().
�
So, I tried to replace the call (at yellow line here below):
�
free(cairo_surface);
�
with a:
�
cairo_surface_destroy(cairo_surface);
�
I rebuilt osgdb_svg.dll, and now it seems to work. I can load any .svg file and use as a texture with no crash.
But I still wonder if that replacement really deallocates the memory allocated for the cairo surface.