forked from bartvdbraak/blender
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.
This commit is contained in:
parent
d400c083b8
commit
31fe70019d
@ -142,8 +142,8 @@ char blender_path[FILE_MAXDIR+FILE_MAXFILE] = BLENDERPATH;
|
|||||||
/* Initialise callbacks for the modules that need them */
|
/* Initialise callbacks for the modules that need them */
|
||||||
static void setCallbacks(void);
|
static void setCallbacks(void);
|
||||||
|
|
||||||
/* on linux set breakpoints here when running in debug mode, useful to catch floating point errors */
|
/* set breakpoints here when running in debug mode, useful to catch floating point errors */
|
||||||
#if defined(__sgi) || defined(__linux__) || OSX_SSE_FPE
|
#if defined(__sgi) || defined(__linux__) || defined(_WIN32) || OSX_SSE_FPE
|
||||||
static void fpe_handler(int sig)
|
static void fpe_handler(int sig)
|
||||||
{
|
{
|
||||||
// printf("SIGFPE trapped\n");
|
// 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)
|
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!
|
/* zealous but makes float issues a heck of a lot easier to find!
|
||||||
* set breakpoints on fpe_handler */
|
* set breakpoints on fpe_handler */
|
||||||
signal(SIGFPE, fpe_handler);
|
signal(SIGFPE, fpe_handler);
|
||||||
|
|
||||||
# if defined(__linux__) && defined(__GNUC__)
|
# if defined(__linux__) && defined(__GNUC__)
|
||||||
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
|
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
|
||||||
#else
|
# endif /* defined(__linux__) && defined(__GNUC__) */
|
||||||
# if OSX_SSE_FPE
|
# if OSX_SSE_FPE
|
||||||
/* OSX uses SSE for floating point by default, so here
|
/* OSX uses SSE for floating point by default, so here
|
||||||
* use SSE instructions to throw floating point exceptions */
|
* use SSE instructions to throw floating point exceptions */
|
||||||
_MM_SET_EXCEPTION_MASK(_MM_MASK_MASK &~
|
_MM_SET_EXCEPTION_MASK(_MM_MASK_MASK &~
|
||||||
(_MM_MASK_OVERFLOW|_MM_MASK_INVALID|_MM_MASK_DIV_ZERO));
|
(_MM_MASK_OVERFLOW|_MM_MASK_INVALID|_MM_MASK_DIV_ZERO));
|
||||||
# endif /* OSX_SSE_FPE */
|
# endif /* OSX_SSE_FPE */
|
||||||
#endif /* defined(__linux__) && defined(__GNUC__) */
|
# 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
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user