[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29013] trunk/blender/source/creator/ creator.c: Add floating-point exception handler trap for Windows (MSVC).

Nathan Letwory jesterking at letwory.net
Thu May 27 01:03:25 CEST 2010


Revision: 29013
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29013
Author:   jesterking
Date:     2010-05-27 01:03:25 +0200 (Thu, 27 May 2010)

Log Message:
-----------
Add floating-point exception handler trap for Windows (MSVC). Now you can set breakpoint on fpe_handler on Windows too when debugging floating-point funkyness.

Modified Paths:
--------------
    trunk/blender/source/creator/creator.c

Modified: trunk/blender/source/creator/creator.c
===================================================================
--- trunk/blender/source/creator/creator.c	2010-05-26 20:09:26 UTC (rev 29012)
+++ trunk/blender/source/creator/creator.c	2010-05-26 23:03:25 UTC (rev 29013)
@@ -142,8 +142,8 @@
 /* Initialise callbacks for the modules that need them */
 static void setCallbacks(void); 
 
-/* on linux set breakpoints here when running in debug mode, useful to catch floating point errors */
-#if defined(__sgi) || defined(__linux__) || OSX_SSE_FPE
+/* set breakpoints here when running in debug mode, useful to catch floating point errors */
+#if defined(__sgi) || defined(__linux__) || defined(_WIN32) || OSX_SSE_FPE
 static void fpe_handler(int sig)
 {
 	// printf("SIGFPE trapped\n");
@@ -362,21 +362,24 @@
 
 static int set_fpe(int argc, char **argv, void *data)
 {
-#if defined(__sgi) || defined(__linux__) || OSX_SSE_FPE
+#if defined(__sgi) || defined(__linux__) || defined(_WIN32) || OSX_SSE_FPE
 	/* zealous but makes float issues a heck of a lot easier to find!
 	 * set breakpoints on fpe_handler */
 	signal(SIGFPE, fpe_handler);
 
-#if defined(__linux__) && defined(__GNUC__)
+# if defined(__linux__) && defined(__GNUC__)
 	feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
-#else
-#if OSX_SSE_FPE
+# endif	/* defined(__linux__) && defined(__GNUC__) */
+# if OSX_SSE_FPE
 	/* OSX uses SSE for floating point by default, so here 
 	 * use SSE instructions to throw floating point exceptions */
 	_MM_SET_EXCEPTION_MASK(_MM_MASK_MASK &~
 						   (_MM_MASK_OVERFLOW|_MM_MASK_INVALID|_MM_MASK_DIV_ZERO));
-#endif	/* OSX_SSE_FPE */
-#endif	/* defined(__linux__) && defined(__GNUC__) */
+# endif	/* OSX_SSE_FPE */
+# if defined(_WIN32) && defined(_MSC_VER)
+	_controlfp_s(NULL, 0, _MCW_EM); /* enables all fp exceptions */
+	_controlfp_s(NULL, _EM_DENORMAL | _EM_UNDERFLOW | _EM_INEXACT, _MCW_EM); /* hide the ones we don't care about */
+# endif /* _WIN32 && _MSC_VER */
 #endif
 
 	return 0;





More information about the Bf-blender-cvs mailing list