wgl: Disable CRT message boxes when Windows system error messages boxes are disabled.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 3 Jun 2014 17:08:34 +0000 (18:08 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 4 Jun 2014 09:25:08 +0000 (10:25 +0100)
At least on MSVC we statically link against the CRT, so we must disable
the CRT message boxes if we want unattended testing.

The messages are convenient when running manually, so let them be if the
system error message boxes are not disabled.

src/gallium/auxiliary/util/u_debug.c
src/gallium/auxiliary/util/u_debug.h
src/gallium/state_trackers/wgl/stw_device.c

index dc840e8566c0b190059dba72efaf393cd64a26bc..d79f31ea947b9c894dd3bc5396442fe1ef22cfbb 100644 (file)
 #include <limits.h> /* CHAR_BIT */
 #include <ctype.h> /* isalnum */
 
+#ifdef _WIN32
+#include <windows.h>
+#include <stdlib.h>
+#endif
+
+
 void _debug_vprintf(const char *format, va_list ap)
 {
    static char buf[4096] = {'\0'};
@@ -64,6 +70,32 @@ void _debug_vprintf(const char *format, va_list ap)
 }
 
 
+void
+debug_disable_error_message_boxes(void)
+{
+#ifdef _WIN32
+   /* When Windows' error message boxes are disabled for this process (as is
+    * typically the case when running tests in an automated fashion) we disable
+    * CRT message boxes too.
+    */
+   UINT uMode = SetErrorMode(0);
+   SetErrorMode(uMode);
+   if (uMode & SEM_FAILCRITICALERRORS) {
+      /* Disable assertion failure message box.
+       * http://msdn.microsoft.com/en-us/library/sas1dkb2.aspx
+       */
+      _set_error_mode(_OUT_TO_STDERR);
+#ifdef _MSC_VER
+      /* Disable abort message box.
+       * http://msdn.microsoft.com/en-us/library/e631wekh.aspx
+       */
+      _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
+#endif
+   }
+#endif /* _WIN32 */
+}
+
+
 #ifdef DEBUG
 void debug_print_blob( const char *name,
                        const void *blob,
index 9c414211b3fc43dc777347618d727ebbf232a908..badd5e296f6bdb85467b0181cbb1bf0dd9614551 100644 (file)
@@ -138,6 +138,15 @@ void debug_print_format(const char *msg, unsigned fmt );
 #endif
 
 
+/**
+ * Disable interactive error message boxes.
+ *
+ * Should be called as soon as possible for effectiveness.
+ */
+void
+debug_disable_error_message_boxes(void);
+
+
 /**
  * Hard-coded breakpoint.
  */
index 8f2cf9c7a1c09e6315671d8f58a47028ccfd19e0..025dbdc838426cc80e264b31847ac9fba7478186 100644 (file)
@@ -69,6 +69,8 @@ stw_init(const struct stw_winsys *stw_winsys)
    static struct stw_device stw_dev_storage;
    struct pipe_screen *screen;
 
+   debug_disable_error_message_boxes();
+
    debug_printf("%s\n", __FUNCTION__);
    
    assert(!stw_dev);