memory corruption

"E.D. Epperson" <[email protected]> Tue, 2 Oct 2012 08:09:55 -0400 (EDT)
Newsgroups gmane.comp.gnome.lib.librsvg.devel
Message-ID <882548609.294722.1349179795333.JavaMail.root@md11.insight.synacor.com>
I've two issues with the code below and would appreciate if someone could help me with this.  This runs as a C# dll

First issue, I cannot save jpeg.  When I get to this line, gdk_pixbuf_save(pixbuf, rsltPath, formattype, out error); I get an access violation.  

The second issue is, I am running this from a web server.  My web page will hit and send up to 28 svg images to convert to png.  So the first time the web page hits, it will process all the images.  But the second time a web page wants to convert svg to png, I get an access violation  on this line:  rsvg_handle_new_from_file(tempsvg, out error);

I don't think I'm handling my memory correctly, but not sure what to do.  


private void RasterizeSvg(string tempsvg, string rsltPath, int _width, int _height, string formattype)
{
    string slib = ConfigurationManager.AppSettings["LibrSvgPath"];
    if (slib == null)
    {
        slib = @"C:\Librsvg";
    }
    bool callSuccessful = SetDllDirectory(slib); 
    if (!callSuccessful)
    {
        throw new Exception("Could not set DLL directory");
    }

    // g_type_init is critical for the png to save correctly
    g_type_init();
    IntPtr error = IntPtr.Zero;
    IntPtr rsvghandle = rsvg_handle_new_from_file(tempsvg, out error);
    if (error != IntPtr.Zero)
    {
        throw new Exception(Marshal.ReadInt32(error).ToString());
    }
    rsvg_handle_close(rsvghandle, out error);
    if (error != IntPtr.Zero)
    {
        throw new Exception(Marshal.ReadInt32(error).ToString());
    }
    IntPtr cairosurface = cairo_image_surface_create(cairo_format_t.CAIRO_FORMAT_RGB24, _width, _height);
    IntPtr cairorenderer = cairo_create(cairosurface);
    bool brslt = rsvg_handle_render_cairo(rsvghandle, cairorenderer);

    cairo_destroy(cairorenderer);
    if (formattype == "png")
    {
        cairo_surface_write_to_png(cairosurface, rsltPath);
        cairo_destroy(cairosurface);
    }
    else
    {
        //jpeg not working.  the problem is how to convert from a cairo surface to a pixbuf
        // once we figure that out, we can implement the jpeg conversion

        /*option 1*/
        //IntPtr pixbuf = cairo_create(cairosurface);
        //cairo_set_source_surface(pixbuf, cairosurface, 0, 0);
        //cairo_rectangle(pixbuf, 0, 0, _width, _height);
        //cairo_fill(pixbuf);
        //error = IntPtr.Zero;                

        /*option 2*/
        IntPtr pixbuf = rsvg_handle_get_pixbuf(rsvghandle);

        cairo_destroy(cairosurface);

        callSuccessful = gdk_pixbuf_save(pixbuf, rsltPath, formattype, out error);
        if (!callSuccessful)
        {
            throw new Exception(error.ToInt32().ToString());
        }
    }
    g_object_unref(rsvghandle);
}

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev

_______________________________________________
Librsvg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/librsvg-devel