[osg-users] a couple of questions about svg plugin (OSG 3.0.1)

83 views
Skip to first unread message

Gianluca Natale

unread,
Dec 13, 2012, 7:11:16 AM12/13/12
to osg-...@lists.openscenegraph.org

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

 

Robert Osfield

unread,
Dec 13, 2012, 9:50:54 AM12/13/12
to OpenSceneGraph Users
Hi Guanluca,

I've only used librsvg from the Ubunutu/debian repositories and haven't come across problems before.  Perhaps there is a version issue, or perhaps an issue with librsvg handling the .svg you are passing on.  As you are working under Windows I think it may well be simply down to the libs and the OSG being built with different options, this is a very common issue for Windows programmers and comes with the territory am I afraid, it's another one of the reasons that I haven't touched windows development for a decade. 

As for rendering svg using the scene graph/OpenGL rather than rendering to a CPU based image then texturing this, we'll it's possible but a for more complex issue than just relying upon a 3rd party lib to the handle all the specifics of vector graphics.  NVidia do have a library that does vector graphics ontop of OpenGL so this is probably the way one would tackle it.

Robert.

_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Gianluca Natale

unread,
Dec 13, 2012, 10:01:55 AM12/13/12
to OpenSceneGraph Users

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)

Gianluca Natale

unread,
Dec 14, 2012, 1:19:07 PM12/14/12
to OpenSceneGraph Users

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)

Jason Daly

unread,
Dec 14, 2012, 1:44:17 PM12/14/12
to OpenSceneGraph Users
On 12/14/2012 01:19 PM, Gianluca Natale wrote:

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.


Hi, Gianluca,

This change has already been made in SVN (r12945, by Jason Beverage).� The log indicates the change was made because it was causing a crash in Windows.

From my experience in using cairo for several years, this is the correct way to destroy a cairo surface.� Using free was a bug from the beginning, as cairo surfaces (like all cairo objects) are internally reference counted.

--"J"


Reply all
Reply to author
Forward
0 new messages