Crash while reading SVG image from blob

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
drunkensapo
Posts: 23
Joined: 2013-08-14T15:40:56-07:00
Authentication code: 6789

Crash while reading SVG image from blob

Post by drunkensapo »

Dear all,
I'm using Magick++ to render a SVG image to PNG with the code shown below. Image_t* is just an alias for Magick::Image. svg_str contains the SVG's XML stores as a string, and size is the desired output size. This code works on a regular PC, but when I go mobile (ios) it crashes.
I've narrowed down the problem to a point I can't proceed. The crash is due to magick being unable to read a temporary file. My explanation is the following, to convert to SVG, the read method first saves a temporary, invokes some sort of command line executable (via system call) and then tries to read the output of that command. Thus, as the writing succeeds there is no "write exception", but only a "read exception", because the system call failed. For example, you can't call "convert" in iOS.
BTW, I'm pretty sure it is not a path problem because I'm setting MAGICK_TMPDIR and MAGICK_TEMPORARY_PATH to writable places in the device, and I'm able to see some tmp files there.

So, my questions are the following:
1) Can you confirm my guess that some tmp writing is going on?
2) If affirmative, is there any way to avoid it for SVG->PNG rendering?
3) How can I debug this in a deeper way?

Thanks in advance.
Best,
Juan

Code: Select all

Image_t* MaskGenerator::createWithSvg(std::string svg_str, Magick::Geometry size)
{

	Image_t *svg_image = gstNew Image_t();

	svg_image->backgroundColor(Magick::Color(0x0, 0x0, 0x0, QuantumRange));

	Geometry density = Geometry(500, 500);
	svg_image->resolutionUnits(PixelsPerInchResolution);
	svg_image->density(density);

	Magick::Blob svg_blob(svg_str.c_str(), svg_str.length());
	svg_image->magick("SVG");
	try{
		svg_image->read(fname_tmp);
	}catch(Magick::Warning &w)
	{
		xml_out("Magick Warning in read SVG blob\n");
		xml_out("%s",w.what());
	}
	svg_image->resize(size);
	
	return svg_image;
}
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Crash while reading SVG image from blob

Post by snibgo »

drunkensapo wrote:1) Can you confirm my guess that some tmp writing is going on?
If IM is delegating to an external program (eg Inkscape) then, yes.
drunkensapo wrote:2) If affirmative, is there any way to avoid it for SVG->PNG rendering?
You could ensure it doesn't delegate, eg by using "MSVG:myfile.svg".
drunkensapo wrote:3) How can I debug this in a deeper way?
If the problem is that IM can read the file created by the delegate, perhaps the delegate failed. What delegate is used? Can it correctly process the SVG independently of IM?
snibgo's IM pages: im.snibgo.com
drunkensapo
Posts: 23
Joined: 2013-08-14T15:40:56-07:00
Authentication code: 6789

Re: Crash while reading SVG image from blob

Post by drunkensapo »

If the problem is that IM can read the file created by the delegate, perhaps the delegate failed. What delegate is used? Can it correctly process the SVG independently of IM?
No, IM can't read the file created by the delegate, because if the SVG delegate runs from command line, it is impossible to run it on mobile device with the current IM port I've made.
The exception thrown is exactly that, it can't read the generated file because it doesn't exist.

On the other hand, I've tried this:
You could ensure it doesn't delegate, eg by using "MSVG:myfile.svg".
And doesn't seem to change anything. How can I test which delegate is ACTUALLY running?
Thanks for your time.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Crash while reading SVG image from blob

Post by snibgo »

Instead of "MSVG:", try "MVG:".
drunkensapo wrote:How can I test which delegate is ACTUALLY running?
I don't know how to do that within a program.

At the command line, "-verbose" will tell you what delegate IM has asked for, and whether it has worked.

If an external delegate (ie a program external to IM) is actually being run, your OS will have a facility to report this. But if your OS doesn't permit IM to run external delegates, I don't know how you would fix that.
snibgo's IM pages: im.snibgo.com
drunkensapo
Posts: 23
Joined: 2013-08-14T15:40:56-07:00
Authentication code: 6789

Re: Crash while reading SVG image from blob

Post by drunkensapo »

I didn't want to fix it. Just understood that Magick had its own converter, thus there was no need to use an external delegate. I finally ended rendering SVG with an external code and placing it into a Magick::Image.
Thanks for your time.
Post Reply