Page 1 of 1

Reading images causes unclear exception

Posted: 2014-08-16T12:15:39-07:00
by nemo.caligo
Hi!

I've been experiencing some problems when I try to read an Image object. I tried to search on Google using multiple queries, but I didn't manage to find any answer to this.

My problem is the following: Whenever I run the script below, I either get an unhandled exception (see quote #2), or the try/catch catches an exception and outputs something along the lines of quote #1. Why I say "something along the lines of", is mainly because these: "`@|ý'", always change. If I'm lucky, it tells me it can't open image #CCCCCC, which is somewhat correct, because then it takes the correct value of the string, excluding the first three characters. This doesn't seem to happen when I use an image file-name (meaning it always throws these strange (@|ý') characters instead).

Please note that I got both of these errors while trying to run the script multiple times using the same code without making any changes to my environment.

QUOTE #1
Caught exception: app.exe: unable to open image `@|ý': Invalid arg
ument @ error/blob.c/OpenBlob/2658
What is it referring to when it says invalid argument? Does it mean the argument I pass to read()? If that's the case, then what am I supposed to pass there, if not a color in hex, and not a file-name? Hell, I even tried copy/ pasting a tutorial to no avail.

QUOTE #2
Unhandled exception at 0x5e841ed7 in app.exe: 0xC0000005: Access violation reading location 0x002f0000.

Code: Select all

#include "stdafx.h"
#include <iostream>
#include "Magick++.h"

using namespace std;
using namespace Magick;

int _tmain(int argc, _TCHAR* argv[])
{
	// InitializeMagick("XXX\ImageMagick-6.8.9-Q16"); // <-- Is this necessary? Note it didn't change anything regarding my current error

	Image image;

	try
	{
		string backGround = "xc:#CCCCCC"; // <-- Borrowed this line from button.cpp
		image.read(backGround); // <-- This is the line that causes everything to blow up
	}
	catch( Exception &error_ ) 
	{ 
		cout << "Caught exception: " << error_.what() << endl; 
	}

	int capish = 0;
	while (capish == 0)
	{
		cout << endl << endl << "Capish?" << endl;
		cin >> capish;
	}

	return 0;
}
After I realized my initial code wouldn't work, I took some things from the demo for button.cpp, and that's why I use backGround instead of an image file-name, because then I assumed it'd certainly work because the image path couldn't be incorrect (because you know, it's sort of, ish, a color and not a path to a file on my system). It seems I was wrong.

(Please note that before I did the things mentioned above, I did try the first piece of code on this page: http://www.imagemagick.org/Magick++/Image.html, though, that didn't work either. I've tried reading a PNG, and, like the code in the link does, a GIF. None of them worked.)

If I comment out "image.read(backGround);", the errors disappear. Of course though, nothing (as in no images) are loaded/ read either.

I use MSVC++ 2010 Express.
I tried to open the example projects, but the project files couldn't be converted for some reason, which is why I'm attempting to create this from a scratch project.

This is the version I use of ImageMagick: ImageMagick-6.8.9-Q16

If someone could try and help me figure out/ explain to me why I am getting these errors/ where I can read more about them, it'd be greatly appreciated (mostly referring to quote #1).

Thanks in advance,
/Nemo

Re: Reading images causes unclear exception

Posted: 2014-08-16T12:39:59-07:00
by snibgo
I know almost nothing about Magick++, but have you successfully compiled and run the demo programs? When you have the appropriate IM libraries and you know the correct incantations to the compiler and linker etc, you can use the same on your own programs. If they don't work, you know it isn't a bug in your source code.

You might also search these forums for MSVC Express. The topic has been mentioned a few times.

With Cygwin on Windows 8.1, the Magick++ demo programs compiled and ran for me without any problems.

I've documented the process for Cygwin (the top few pages on my web site), but I don't know how transferrable that is to MSVC.

Re: Reading images causes unclear exception

Posted: 2014-08-16T19:54:56-07:00
by nemo.caligo
Hi snibgo, and thank you for your reply!

Unfortunately, searching the forums didn't give much results.

Regarding cygwin, I told myself I'd go with it if nothing else worked, mostly cus I've been tired all day and didn't really feel like setting it up. I attempted to search some more on Google and found this blog-entry (I figured I'd just try searching for "imagemagick msvc", like you suggested I'd do on the forums) on a website: http://fortunomedia.com/magick-plus-plus-config-vs2010/

Apparently, for some reason, Microsoft Visual C++ 2010 doesn't like compiling ImageMagick in debug-mode, at all. Setting it to release (and configuring release-mode as well to include all the headers and libraries and dependencies), solved my issue. I still don't really know how that's related to not being able to find the images though.

Hopefully this will help people find a simple solution to this problem. I sure as hell had a very hard time finding a solution to this. Then yet again, I didn't really have any idea what to search for since I didn't really know what the problem was.

Thanks again,
/Nemo

Re: Reading images causes unclear exception

Posted: 2014-08-17T08:55:58-07:00
by snibgo
Good stuff, I'm glad it works.

Searching for "MSVC express" in these forums, the first page listed after this one is Open file fails in MSVC debug mode.

Re: Reading images causes unclear exception

Posted: 2014-08-17T10:27:44-07:00
by nemo.caligo
Oh, yes it did. Sorry, I totally missed that. I also posted in the wrong forums (I just realized there's a specific sub-forum for Magick++). It got late yesterday and I wasn't paying attention to things.

But yeah, it's working now, so thanks!
/Nemo