Page 1 of 1

"Access violation writing" exception while creating an Image

Posted: 2010-02-19T00:24:08-07:00
by hakiim35
Hello, i receive a weird exception in my application.
I have a public Image member in my class. When i push a button in my gui, i want to read an image from disk..
but i receive an "Access violation writing" exception in my callback function. Below is a pseudocode of the application.

Code: Select all

#include <Magick++.h>
#include <iostream> 
using namespace std; 
using namespace Magick; 

class X
{
public:
    X();
   ~X();
    Image img;
}

void X::mycallback()
{
	try { 
	   img.read("cat.bmp");
	   img.write("out.jpg");
	}
	catch( Exception &error_ ) { 
            cout << "Caught exception: " << error_.what() << endl; 
            return; 
        } 
}
I am developing the gui by using QT. I can give the detailed code if it is needed.
In the debug mode, the exception is thrown on "img.read" line.
Any idea is appreciated.
Regards,

Re: "Access violation writing" exception while creating an I

Posted: 2010-02-19T05:35:46-07:00
by magick
What version of ImageMagick are you using? What operating system are you using?

Re: "Access violation writing" exception while creating an I

Posted: 2010-02-19T06:01:09-07:00
by hakiim35
Hello, i m using ImageMagick-6.5.9-Q16 on Windows XP 32 bit.
Thanks.

Re: "Access violation writing" exception while creating an I

Posted: 2010-02-19T07:01:19-07:00
by magick
Ok, go to c:\Program Files\ImageMagick-6.5.9-Q16\Magick++_demos and click on the Button workspace. Build and execute. Presumably it will compile and run without complaint. Now use the Button workspace as a model for your own custom program. It has all the required settings for a proper Magick++ build.

Re: "Access violation writing" exception while creating an I

Posted: 2010-02-22T01:33:09-07:00
by hakiim35
Ok i have carried the same configuration to my Visual c++.NET project, same error continues to happen. The weird thing is, when i put the mouse cursor on the member Image img; it shows a tooltip that the member belongs to MagickCore::Image class. But while I am initializing it in the constructor or in a member method, it wont recognize img.read("lena.jpg"), it wont also recognize write or zoom functions..Any idea?

Re: "Access violation writing" exception while creating an I

Posted: 2010-02-25T02:31:53-07:00
by hakiim35
Hi again,
i can now write an image to file by giving a target path manually, inside the code; but it wont write the image when the target is a dynamically allocated local string pointer.
For instance, in my save() method, the following piece of code works

Code: Select all

img = new Image("lena.jpg");
img->magick("JPEG");
img->quality(0);
img->write("C:\\trial.jpg);
but when the target string is chosen by a File dialog, and the reference of it is sent to the write function as in the following code, it gives an exception like "Unhandled exception at 0x7855ab1a in blabla.exe: 0xC0000005: Access violation reading location 0xbaadf00d."

Code: Select all

img = new Image("lena.jpg");
img->magick("JPEG");
img->quality(0);		
string * target = new string(filename.toStdString());
img->write(*target);
here before sent to the write, I comfirm in debug mode that the target pointer is properly set with the correct destination directory.
filename is a member of the class which owns the save method.
Any idea is well appreciated.
Thanks.

Re: "Access violation writing" exception while creating an I

Posted: 2010-02-25T04:03:46-07:00
by hakiim35
I think it is related with the target file name.
File name should contain \\ instead of \ to reach child folder.
For instance "C:\target.jpg" is not valid while "C:\\target.jpg" is valid.
Small but an annoying point.