What am i doing wrong?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
robthebloke

What am i doing wrong?

Post by robthebloke »

The following code doesn't do a great deal :( I've also tried writing images but the only sucess i've had so far is to make it crash.

Code: Select all

int main(int argc,char** argv)
{
  InitializeMagick(*argv);
  Image my_image(); 
  try
  {
    my_image.read("C:/test.bmp"); // *epic crash*
  }
  catch(...)
  {
  }
  return 1;
}
I'm running windows vista, and VC++ 2005 if that's any help. any ideas?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: What am i doing wrong?

Post by magick »

When you install the ImageMagick Windows binary distribution, Magick++ demos are included. Go to c:\Program Files\ImageMagick-6.4.2-Q16\Magick++_demos and launch the button project. Build and run. Now use this project as a template for your own development.
robthebloke

Re: What am i doing wrong?

Post by robthebloke »

yup. That crashes as well....
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: What am i doing wrong?

Post by magick »

We did a fresh install on our Vista system of http://www.imagemagick.org/download/bin ... ws-dll.exe and built the button project with Visual Studio 2005. When we run the project it created button_out.miff as expected without complaint. Not sure why its failing for you.
robthebloke

Re: What am i doing wrong?

Post by robthebloke »

Out of interest, are the binaries compiled with VC++2003?

I notice you have the VC7 runtimes included in the distribution....
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: What am i doing wrong?

Post by magick »

The ImageMagick Windows binaries are build with Visual Studio 2003. We also have 2005 and 2008 to verify ImageMagick works with these IDE's as well.
robthebloke

Re: What am i doing wrong?

Post by robthebloke »

I thought so. I'll take a stab in the dark and suggest that the problem is very likely to be as a result of C4251 (since the symptoms i'm seeing are ones i've had to fix in our own public API's before - which we fixed by removing all traces of STL from exposed DLL classes and funcs). It's a very bad idea to pass STL objects across DLL bounds without first correctly exporting the templates....
robthebloke

Re: What am i doing wrong?

Post by robthebloke »

Ok. One thing of note is that the button example only includes a a release configuration (i actually added the debug config thinking that the conversion wizard had screwed up and not converted it, i.e. /MDd, _DEBUG, optimisations off), if however you run a debug version of button, you get:

Image

I'm still experiencing some problems with occasional crashes in release as well (I can at least read and write an image) . I'm going to take a stab in the dark and say the problem is probably this this (note the comment at the very bottom). Since STL that is included with 2005 includes loads more security checks, iterator debugging etc, (i.e. all of that fscanf_s crap) the versions match enough to the old versions as to not cause problems linking, but do cause problems due to differences in internal data representations.

Therefore you get problems with containers when you pass them across the DLL bounds. The dll internally will assume the data it recieves is in the same layout as the template the dll saw when it was compiled. This however is not the case. As a result, you get problems with the data that the DLL recieves. When i first tried to integrate image magick into my project, i got warnings about the following classes (due to enabling warning level 4).

list<Magick::Coordinate>
list<Magick::Drawable>
list<Magick::VPath>
list<Magick::PathArcArgs>
list<Magick::PathCurvetoArgs>
list<Magick::PathQuadraticCurvetoArgs>

I noticed the button example doesn't generate these warnings, but with a bit of digging i found this (line:65, Include.h)

Code: Select all

#    if defined(_VISUALC_)
#      pragma warning( disable: 4273 )  /* Disable the stupid dll linkage warnings */
#      pragma warning( disable: 4251 )
#    endif
Which i'm guessing aren't that stupid ;) The best bet (imo) is to build a distribution with the following dll's

Code: Select all

<DllName>_2003.dll
<DllName>_2003_debug.dll
<DllName>_2005.dll
<DllName>_2005_debug.dll
<DllName>_2008.dll
<DllName>_2008_debug.dll
and corresponding libs. (assuming that you only care about /MD and /MDd - you could also go mental and do /MT and /MTd as well.. ). I have a feeling that's the probably cause of the crashes. Unfortunately i don't have a copy of 2003 around, but i'm guessing a debug version of button in 2003 probably works...

If you get a chance, can you see if you get a crash with a 2005/2008 debug build of button?
Post Reply