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.

SetErrorMode in windows version of ImageMagick

Postby findus » 2013-09-17T06:24:24+00:00

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/windows/desktop/ms680621(v=vs.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/windows/desktop/ms679355(v=vs.85).aspx
Last edited by findus on 2013-09-18T06:13:28+00:00, edited 1 time in total.
findus
 
Posts: 14
Joined: 2012-08-14T07:57:42+00:00

Re: SetErrorMode in windows version of ImageMagick

Postby dlemstra » 2013-09-18T00:11:36+00:00

The following patch has been applied:
Code: Select all
mode=GetErrorMode();
mode=SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
.NET + ImageMagick = Magick.NET https://magick.codeplex.com, @MagickNET, Donate
User avatar
dlemstra
 
Posts: 426
Joined: 2013-05-04T15:28:54+00:00

Re: SetErrorMode in windows version of ImageMagick

Postby findus » 2013-09-18T01:29:12+00:00

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?
findus
 
Posts: 14
Joined: 2012-08-14T07:57:42+00:00

Re: SetErrorMode in windows version of ImageMagick

Postby dlemstra » 2013-09-18T04:19:07+00:00

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://magick.codeplex.com, @MagickNET, Donate
User avatar
dlemstra
 
Posts: 426
Joined: 2013-05-04T15:28:54+00:00


Return to Developers

Who is online

Users browsing this forum: No registered users and 8 guests