diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2010-05-27 03:03:25 +0400 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2010-05-27 03:03:25 +0400 |
commit | 31fe70019d96c79131c6047aeb08ce137aaa0208 (patch) | |
tree | 9b535085f07843ae62b828c9ef23f4eaeb2bcaa2 /source/creator | |
parent | d400c083b8d1ea104cf0523c59e296162a7c782c (diff) |
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.
Diffstat (limited to 'source/creator')
-rw-r--r-- | source/creator/creator.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c index 429646fe5b6..2d1125e75ce 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -142,8 +142,8 @@ char blender_path[FILE_MAXDIR+FILE_MAXFILE] = BLENDERPATH; /* 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 debug_mode(int argc, char **argv, void *data) 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; |