"Access violation writing" exception while creating an Image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hakiim35
Posts: 19
Joined: 2010-02-18T07:04:01-07:00
Authentication code: 8675308

"Access violation writing" exception while creating an Image

Post 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,
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

What version of ImageMagick are you using? What operating system are you using?
hakiim35
Posts: 19
Joined: 2010-02-18T07:04:01-07:00
Authentication code: 8675308

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

Post by hakiim35 »

Hello, i m using ImageMagick-6.5.9-Q16 on Windows XP 32 bit.
Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
hakiim35
Posts: 19
Joined: 2010-02-18T07:04:01-07:00
Authentication code: 8675308

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

Post 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?
hakiim35
Posts: 19
Joined: 2010-02-18T07:04:01-07:00
Authentication code: 8675308

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

Post 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.
hakiim35
Posts: 19
Joined: 2010-02-18T07:04:01-07:00
Authentication code: 8675308

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

Post 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.
Post Reply