Page 1 of 1
magick++ exception, cannot write to memory location
Posted: 2008-10-11T06:00:47-07:00
by spesho
I did everything following guides/demos/sample code.
still i got a vc++ memory exception on opening a file. no matter whether the path to the file is correct.
Code: Select all
Unhandled exception at 0x10023f45 in CPP.Radon.transform.exe: 0xC0000005: Access violation writing location 0xcda98d72.
This is my code, quite straight forward. My only concern is the initialization of Magick!. is couldnt find something lik Magick::isInitialized()???? nor the method throws any c++::std exception!
Code: Select all
#include <iostream>
#include <conio.h>
#include <Magick++.h>
using namespace std;
//using namespace Magick;
#if _DEBUG
const char* IN_DLL = "C:\\work\\CPP\\radon.trans\\CPP.Radon.transform\\bin\\Debug";
const char* IN_FILE = "xxxsmile.miff";
#endif
int main(int argc, char** argv) {
#if _DEBUG
Magick::InitializeMagick(IN_DLL);
#else
Magick::InitializeMagick(*argv);
#endif
try {
// Construct an image instance first so that we don't have to worry
// about object construction failure due to a minor warning exception
// being thrown.
Magick::Image image;
try {
// Try reading image file
image.read(IN_FILE);
}
catch( Magick::WarningCoder &warning )
{
// Process coder warning while loading file (e.g. TIFF warning)
// Maybe the user will be interested in these warnings (or not).
// If a warning is produced while loading an image, the image
// can normally still be used (but not if the warning was about
// something important!)
cerr << "Coder Warning: " << warning.what() << endl;
}
catch( Magick::Warning &warning )
{
// Handle any other Magick++ warning.
cerr << "Warning: " << warning.what() << endl;
}
catch( Magick::ErrorFileOpen &error )
{
// Process Magick++ file open error
cerr << "Error: " << error.what() << endl;
//continue; // Try next image.
}
try {
image.rotate(90);
image.write("outfile");
}
catch ( Magick::Error & error)
{
// Handle problem while rotating or writing outfile.
cerr << "Caught Magick++ exception: " << error.what() << endl;
}
}
catch( std::exception &error )
{
// Process any other exceptions derived from standard C++ exception
cerr << "Caught C++ STD exception: " << error.what() << endl;
}
catch( ... )
{
// Process *any* exception (last-ditch effort). There is not a lot
// you can do here other to retry the operation that failed, or exit
// the program.
}
Please HELP! do not what might be the cause. it is none of the custom exceptions handled above in the code
10x 10x in advance
Re: magick++ exception, cannot write to memory location
Posted: 2008-10-13T05:45:23-07:00
by spesho
OK! a bit of further update. I still cant find the cause of the memory exception on opening a file i got.
The strange think is I managed to build & run the demo projekt for Magick++.
And it does what i want, opening a file!!!!! no exception or error.
the only difference is that for mine I am using VC++ 9 express with clean win32 console app start-up.
For the demo project I opened it with vc++ 8 and converted it from VC++ 6!
There are (were) some differences in the project properties (c++ & linker)
Still I updated my project to match with the slight variation of settings, still no success!
Now I am planing to copy/paste and hack the demo project for my projeckt and see if I have the same strange behavior!
PLEASE, if anyone using VC9 or VC8 has a similar case, let me know!
Re: magick++ exception, cannot write to memory location
Posted: 2008-12-04T07:53:48-07:00
by lindsten
Hi there,
I'm having the exact same problem...
It's been quite a while since I used C++ and back then it was Emacs and gcc. Now I'm using Visual Studio 2008 in a project where I'm assigned the (you would think) simple task of extracting the number of grayscale pages and color pages respectively from a TIFF file.
I know there is the old tifflib, but I thought I would give Magick++ a try since it figured it could be useful knowledge for the future! Downloaded ImageMagick-6.4.6-9-Q16-windows-dll.exe and chose to include header and lib files during the installation.
After struggling to get a simple plain test application (win32 console application) to compile with the Magick++ library (I'm not a friend of Visual Studio), what happens? ...runtime exception when calling image.read()!
"Unhandled exception at 0x100244a5 in TestApp.exe: 0xC0000005: Access violation writing location 0xcda663b0."
The code can not be simpler and I really don't know where to go from here. So please, if you've had any success, enlighten me!
/ Mikael
My code (compiles but doesn't run):
Code: Select all
int _tmain(int argc, _TCHAR* argv[])
{
InitializeMagick("C:\\.......\\Visual Studio 2008\\Projects\\TestApp\\TestApp");
Image image;
try
{
image.read("test.tif");
}
catch(Exception &ex)
{
cout << "Exception: " << ex.what() << endl;
return -1;
}
cout << endl << endl << "Press Enter to quit!"; cin.get();
return 0;
}
Re: magick++ exception, cannot write to memory location
Posted: 2008-12-04T08:10:35-07:00
by magick
Go to C:\Program Files\ImageMagick-6.4.6-9-Q16\Magick++_Demos and launch the button project. Build and run. Most likely it ran without complaint. Now use this project as a template for your own application.
Re: magick++ exception, cannot write to memory location
Posted: 2008-12-04T08:47:27-07:00
by lindsten
I tried the demo project instead since the button project did not read an actual file. As you said, it runs fine. Been looking at it for a while and can't seem to spot any difference from my own test application (other than the demo project is located below the ImageMagick installation folder and my project is not)...
I have copied all the DLLs starting with "CORE_RL" (plus X11.dll) and CORE_RL_Magick++_.lib to my project folder. I have also copied the include directory with Magick++.h and the other header files. I initialize IM to my project folder (where the DLLs are, not the Debug subfolder where the application is run). Am I doing it wrong? (it's hard to tell from the demo projects since their folders are organized differently).
Btw, thanks for you answer! I will keep on trying to get it right...
/ Mikael
Re: magick++ exception, cannot write to memory location
Posted: 2008-12-05T04:27:30-07:00
by lindsten
This is getting to my head!
I have now created an empty win32 console application (within a new solution) in the default projects folder of Visual Studio 2008 (below My Documents), copied all the files and folders from the ImageMagick installation folder to my solution folder, copied the source code from the demo project to my empty project and manually synchronized the project settings of my project and the demo project.
It compiles fine but still crashes with access violation exception when reaching image.read("myfile.tif").
I can only think of one things that differs between the projects. The pathname to my project is much longer than the pathname to the demo project and this is an argument to InitializeMagick(). I guess I'm grasping for air, but are there any limitations here?
What else could possibly be the cause?
I've now spent more than a workday trying to figure this one out. If I can't even get it to work with an empty test project I guess there's no point trying to integrate it into an existing project.
Re: magick++ exception, cannot write to memory location
Posted: 2008-12-22T21:56:10-07:00
by spankster01
magick wrote:Go to C:\Program Files\ImageMagick-6.4.6-9-Q16\Magick++_Demos and launch the button project. Build and run. Most likely it ran without complaint. Now use this project as a template for your own application.
So, I'm having the exact same problem. Even the most simple of test cases causes this error. From your proposed solution (which I haven't been able to try yet, but will as soon as I am able) I have to assume that there is some setting in the Button project file that fixes this problem. Do you know what the setting is, can you just report in the forum what the setting needs to be so that I can fix my code directly?
Edit - So I've been playing around with this more now that I'm home and can access my computer. Sure enough, the "Button" demo builds just fine so I screen captured every different screen of the project settings and compared to my test project created with a clean new console project. I made everything the same and I still got the same error. Then I remembered, the "Button" demo compiles under the "Release" configuration not the "Debug" configuration. So I changed to the release configuration on my test sample and bingo, works like a charm. I'm using Visual C++ Express by the way. So in my test project I've compared the settings between "Release" and "Debug" and have made them identical down to every last option. But still, under Debug I get this error, under Release it works.
Anyone have any ideas why the difference? What does the compiler do differently between Debug and Release? I figured if all the options were set exactly the same that they'd be the same but there must be something going on that is different.....
Thanks!
Mike
Re: magick++ exception, cannot write to memory location
Posted: 2008-12-23T00:34:33-07:00
by spankster01
spankster01 wrote:Anyone have any ideas why the difference? What does the compiler do differently between Debug and Release? I figured if all the options were set exactly the same that they'd be the same but there must be something going on that is different...
Well, I think I have it...... Turns out I didn't quite have all the settings the same. But after a series of experiments and keeping track of all changes/differences between Debug and Release I think I've got it nailed down. In the "Project Properties" page, under "Configuration Properties/C++/Code Generation" make sure the "Runtime Library" is set to "Multi-Threaded DLL (/MD)" and not to "Multi-Threaded Debug DLL (/MDd)" which is the default for the Debug setup. Then under "Configuration Properties/C++/Preprocessor" you have to change the "Preprocessor Definition" that is set to "_DEBUG" to "NDEBUG". I assume that this flag is used in the header files for the Magick++.h files somewhere. When I change these two parameters then everything works in the debug build environment.
I'm gonna call this problem solved (at least it's solved for me), I'd be interested to hear back from the original poster of this thread to see if this fixes his problem. But I've tested it with a clean default project and it works with just these two changes so I think it's correct. I can still debug my code fine (just not the stuff in the runtime or in Magick++ I'd assume, but I wouldn't debug them anyways).
Thanks,
Mike
Re: magick++ exception, cannot write to memory location
Posted: 2009-10-07T10:29:12-07:00
by qsiek
I have some problems with Magick++ since June. Quite quick it took me to solve a problem with dll's which compiler couldn't open but since last month I'm having problems with running my program on any other PC than mine. As long as I'm using my computer it's ok... every method of magick++ works perfect but when I try to run it on other PC every time I try to open an image I get this error:
Code: Select all
{severity=MissingDelegateError error_number=0 reason=0x00d9fe38 "NoDecodeDelegateForThisImageFormat `C:\moj.jpg' @ constitute.c/ReadImage/503" ...} _ExceptionInfo *
Does anybody know why is this running on my computer and won't go on any other?
Thanks in advantage.
Re: magick++ exception, cannot write to memory location
Posted: 2009-10-07T11:04:16-07:00
by magick
One way to ensure it will work on another PC is to download and install the latest ImageMagick Windows distribution. The default is to check Window registry entries for the location of ImageMagick modules and configuration files. The ImageMagick Windows installer ensure there entries are set properly. If you want to just copy the ImageMagick files from PC to PC you need to build ImageMagick yourself. The default build is "uninstalled" meaning it does not depend on Window registry entries. You probably will want to buld a static release rather than the default dynamic release.
Re: magick++ exception, cannot write to memory location
Posted: 2009-10-16T18:15:37-07:00
by qsiek
magick wrote: If you want to just copy the ImageMagick files from PC to PC you need to build ImageMagick yourself. The default build is "uninstalled" meaning it does not depend on Window registry entries. You probably will want to buld a static release rather than the default dynamic release.
allright, I built static multi-threaded release and added the lib path to "additional include directories" and got unresolved external symbol errors... what do I do wrong?
edit:
ok I forgot to add include path...
now another problem
Code: Select all
C:\Documents and Settings\Marcin\Pulpit\ImageMagick-6.5.6-9(2)\ImageMagick-6.5.6-9\Magick++\lib\Magick++/Pixels.h(88) : error C2039: 'CacheView' : is not a member of 'MagickCore'
C:\Documents and Settings\Marcin\Pulpit\ImageMagick-6.5.6-9(2)\ImageMagick-6.5.6-9\Magick++\lib\Magick++/Pixels.h(88) : error C2143: syntax error : missing ';' before '*'
C:\Documents and Settings\Marcin\Pulpit\ImageMagick-6.5.6-9(2)\ImageMagick-6.5.6-9\Magick++\lib\Magick++/Pixels.h(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Documents and Settings\Marcin\Pulpit\ImageMagick-6.5.6-9(2)\ImageMagick-6.5.6-9\Magick++\lib\Magick++/Pixels.h(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Code: Select all
C:\Documents and Settings\Marcin\Pulpit\ImageMagick-6.5.6-9(2)\ImageMagick-6.5.6-9\Magick++\lib\Magick++/Pixels.h(88) : error C2039: 'CacheView' : is not a member of 'MagickCore'
C:\Documents and Settings\Marcin\Pulpit\ImageMagick-6.5.6-9(2)\ImageMagick-6.5.6-9\Magick++\lib\Magick++/Pixels.h(88) : error C2143: syntax error : missing ';' before '*'
C:\Documents and Settings\Marcin\Pulpit\ImageMagick-6.5.6-9(2)\ImageMagick-6.5.6-9\Magick++\lib\Magick++/Pixels.h(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Documents and Settings\Marcin\Pulpit\ImageMagick-6.5.6-9(2)\ImageMagick-6.5.6-9\Magick++\lib\Magick++/Pixels.h(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
does anybody know what does this mean?
Re: magick++ exception, cannot write to memory location
Posted: 2009-10-16T18:59:37-07:00
by magick
There should not be a problem, given ImageMagick is built under Windows / Linux / Mac OS X before each release and we did not receive any compile errors. CacheView is declared in Magick++/Include.h as well.
Re: magick++ exception, cannot write to memory location
Posted: 2009-10-16T19:14:45-07:00
by qsiek
Just for the record, this error that includes Pixel.h shows when I compile my project, not the lib files.
Re: magick++ exception, cannot write to memory location
Posted: 2009-10-17T16:22:46-07:00
by qsiek
ok, i have to be doing something wrong. I'll start from the begining.
You want me to make ImageMagick by myself. So I go to "configure" folder and then run configure and got something like this:
I gotta make static release like you said to be able to run my program on other PC, right?
So which static release I have to choose?
Furthermore, which "build options" do I have to choose in my case or maybe it doesn't make any difference?