SetErrorMode in windows version of ImageMagick

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
findus
Posts: 14
Joined: 2012-08-14T07:57:42-07:00
Authentication code: 67789

SetErrorMode in windows version of ImageMagick

Post 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
Last edited by findus on 2013-09-18T06:13:28-07:00, edited 1 time in total.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: SetErrorMode in windows version of ImageMagick

Post by dlemstra »

The following patch has been applied:

Code: Select all

mode=GetErrorMode();
mode=SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
findus
Posts: 14
Joined: 2012-08-14T07:57:42-07:00
Authentication code: 67789

Re: SetErrorMode in windows version of ImageMagick

Post 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?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: SetErrorMode in windows version of ImageMagick

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply