Page 1 of 1

SetErrorMode in windows version of ImageMagick

Posted: 2013-09-17T06:24:24-07:00
by findus
Hi!

I'm using ImageMagick to read info and convert images in an automated process, and sometimes the reading / conversion fails. This can happen for a number of reasons out of my control, such as corrupt files, corrupt media, access restrictions. Why it fails in the first place is not really important for my suggestion, the point is that it fails sometimes and that i have to deal with that.

I really don't want a windows crash dialog / error report dialog, which is why I use the following snippet of code in my application:

Code: Select all

SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
This suppresses the crash messages that I don't want for my applications, and it is also inherited by other processes that i start. My problem is that ImageMagick seems to set the ErrorMode itself (nt-base.c:1575):

Code: Select all

mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
As you can see there is an option that I use, but is not used in ImageMagick:

Code: Select all

ErrorModes.SEM_NOGPFAULTERRORBOX
This option means: "The system does not display the Windows Error Reporting dialog." See specification: http://msdn.microsoft.com/en-us/library ... s.85).aspx
So when I start ImageMagick from my application, the ErrorMode is inherited and this option is enabled. But ImageMagick sets the ErrorMode itself disabling this option, which makes windows display the error reporting dialog when ImageMagick crashes.

I propose the following two alternative solutions:

1.
Change the call to:

Code: Select all

mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | SEM_NOGPFAULTERRORBOX);
2.
First read the current ErrorMode (possibly inherited by parent process), then add the two current options to them:

Code: Select all

mode=GetErrorMode();
SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
See: http://msdn.microsoft.com/en-us/library ... s.85).aspx

Re: SetErrorMode in windows version of ImageMagick

Posted: 2013-09-18T00:11:36-07:00
by dlemstra
The following patch has been applied:

Code: Select all

mode=GetErrorMode();
mode=SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);

Re: SetErrorMode in windows version of ImageMagick

Posted: 2013-09-18T01:29:12-07:00
by findus
Awsome, thanks a bunch!

In what version of IM will this be included? And when can I expect a windows build to be found that includes this?

Re: SetErrorMode in windows version of ImageMagick

Posted: 2013-09-18T04:19:07-07:00
by dlemstra
This will be included in the next release: ImageMagick 6.8.6-10. I don't know when this will be release but probably very soon.

We did have to add another check since this method needs at least Windows Vista/Windows Server 2008.