Skip to content

Commit

Permalink
Add BREAK_ON_WARNINGS_PRINTS and BREAK_ON_ERROR_PRINTS settings to al…
Browse files Browse the repository at this point in the history
…low easy debugger breaks when an error occurs.
  • Loading branch information
juj committed Apr 30, 2020
1 parent 240bf87 commit 6a05578
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Math/MathFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ bool AssumeFailed()
#endif
}
#endif
// If your debugger is breaking in this function, it means that an assume() failure has occurred,
// or a LOGE()/LOGW() failure has occurred, and building with trap-to-debugger enabled. Navigate
// up the callstack to find the offending code that raised the error.
return mathBreakOnAssume;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Math/MathLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ void PrintToConsole(MathLogChannel channel, const char *str)
}
else
printf("%s\n", str);

#if defined(BREAK_ON_ERROR_PRINTS) || defined(BREAK_ON_WARNING_PRINTS)
if (channel == MathLogError)
AssumeFailed();
#endif

#ifdef BREAK_ON_WARNING_PRINTS
if (channel == MathLogWarning)
AssumeFailed();
#endif
}

#endif
Expand Down
3 changes: 3 additions & 0 deletions src/Math/assume.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@

// The assume() macro operates differently depending on which #defines are present:
// #define FAIL_USING_EXCEPTIONS - the assume() macro throws an exception
// #define BREAK_ON_ERROR_PRINTS - if an error message is printed (with LOGE()), it is treated as if an assume() had failed, breaking to debugger.
// #define BREAK_ON_WARNING_PRINTS - if a warning message is printed (with LOGW()), it is treated as if an assume() had failed, breaking to debugger.
// Implies BREAK_ON_ERROR_PRINTS.
// #define MATH_ASSERT_ON_ASSUME - the assume() macro resolves to the assert() macro.
// #define MATH_STARTUP_BREAK_ON_ASSUME - MathGeoLib execution will start with MathBreakOnAssume() behavior enabled, i.e. assume() failures
// will invoke the debugger. (this behavior can be controlled at runtime with SetMathBreakOnAssume(bool))
Expand Down

0 comments on commit 6a05578

Please sign in to comment.