Magick++ stops at reading an image: Access violation

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Locked
LeFish
Posts: 5
Joined: 2020-03-25T11:33:11-07:00
Authentication code: 1152

Magick++ stops at reading an image: Access violation

Post by LeFish »

For my first program I have the following source:

Code: Select all

#include <iostream>
#include <Magick++.h>
#include <stdio.h>

using namespace std; 
using namespace Magick; 

int main(int argc, char *argv[]) {

    Magick::InitializeMagick(argv[0]);
    
    if (argc < 3)
   {
       printf("Usage: %s <Input file> <Output file>", argv[0]);
        return 1;
   }

   try{
        printf("Opening... %s\n", argv[1]);
        Magick::Image image(argv[1]);
        //printf("Size: %d\n", image.size());

        printf("Rotating...\n");
        image.rotate(45);

        printf("Opening... %s\n", argv[2]);
        image.write(argv[2]);
   }

   catch( Exception &error_ ) 
    { 
      cout << "Caught exception: " << error_.what() << endl; 
      return 1; 
    } 
  return 0;
}
I compile with CMake (->msvc). It basically compiles fine, just a lot of C4251 warning in this form:

Code: Select all

{
	"resource": "/C:/Program Files/ImageMagick-7.0.9-Q8/include/Magick++/Drawable.h",
	"owner": "cmake-build-diags",
	"code": "C4251",
	"severity": 4,
	"message": "\"Magick::PathMovetoRel::_coordinates\": class \"std::vector<Magick::Coordinate,std::allocator<Magick::Coordinate>>\" erfordert eine DLL-Schnittstelle, die von Clients von class \"Magick::PathMovetoRel\" verwendet wird [C:\\Users\\jfi\\Desktop\\Hints_Scripts\\InsortAP_Toolbox\\VSCode\\IMhelloworld_cmake\\build\\IMHelloWorld.vcxproj]",
	"source": "MSVC",
	"startLineNumber": 3133,
	"startColumn": 30,
	"endLineNumber": 3133,
	"endColumn": 30
}
And one C4275 warning

Code: Select all

{
	"resource": "/C:/Program Files/ImageMagick-7.0.9-Q8/include/Magick++/Exception.h",
	"owner": "cmake-build-diags",
	"code": "C4275",
	"severity": 4,
	"message": "class \"std::exception\" ist keine DLL-Schnittstelle und wurde als Basisklasse für die DLL-Schnittstelle class \"Magick::Exception\" verwendet [C:\\Users\\jfi\\Desktop\\Hints_Scripts\\InsortAP_Toolbox\\VSCode\\IMhelloworld_cmake\\build\\IMHelloWorld.vcxproj]",
	"source": "MSVC",
	"startLineNumber": 23,
	"startColumn": 3,
	"endLineNumber": 23,
	"endColumn": 3
}
The program stops when reading the image. It does not give any error message.

Can I add verbosity to magick++?

Thanks for your help!
Last edited by LeFish on 2020-03-30T00:25:08-07:00, edited 2 times in total.

LeFish
Posts: 5
Joined: 2020-03-25T11:33:11-07:00
Authentication code: 1152

Re: Magick++ stops at reading an image

Post by LeFish »

I debugged the program and I think I have found some issue.

I get an Access violation when I read the image:

Image

Can you guys help me?

Thanks!

LeFish
Posts: 5
Joined: 2020-03-25T11:33:11-07:00
Authentication code: 1152

Re: Magick++ stops at reading an image: Access violation

Post by LeFish »

I found out something new:

I can build the program two different ways - Debug or Release

When I build the program as Debug-Version:

Code: Select all

cmake -G NMake Makefiles -DCMAKE_BUILD_TYPE=Debug ..
nmake .
I get the previously described error:

Code: Select all

 Exception thrown at 0x00007FFAEC3EC3F9 (msvcr120.dll) in IMHelloWorld.exe: 0xC0000005: Access violation reading location 0x000000A085B90000.
When I build the program as Release-Version:

Code: Select all

cmake -G NMake Makefiles -DCMAKE_BUILD_TYPE=Release ..
nmake .
I runs just fine!

I found an old post concerning this very problem:

https://www.imagemagick.org/discourse-s ... hp?t=13970

Can you help me building debug libraries from source with Visual Studio Code, please?

Thank you!

Locked