IssueReporting.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. JPH_NAMESPACE_BEGIN
  5. /// Trace function, needs to be overridden by application. This should output a line of text to the log / TTY.
  6. using TraceFunction = void (*)(const char *inFMT, ...);
  7. extern TraceFunction Trace;
  8. // Always turn on asserts in Debug mode
  9. #if defined(_DEBUG) && !defined(JPH_ENABLE_ASSERTS)
  10. #define JPH_ENABLE_ASSERTS
  11. #endif
  12. #ifdef JPH_ENABLE_ASSERTS
  13. /// Function called when an assertion fails. This function should return true if a breakpoint needs to be triggered
  14. using AssertFailedFunction = bool(*)(const char *inExpression, const char *inMessage, const char *inFile, uint inLine);
  15. extern AssertFailedFunction AssertFailed;
  16. // Helper functions to pass message on to failed function
  17. struct AssertLastParam { };
  18. inline bool AssertFailedParamHelper(const char *inExpression, const char *inFile, uint inLine, AssertLastParam) { return AssertFailed(inExpression, nullptr, inFile, inLine); }
  19. inline bool AssertFailedParamHelper(const char *inExpression, const char *inFile, uint inLine, const char *inMessage, AssertLastParam) { return AssertFailed(inExpression, inMessage, inFile, inLine); }
  20. /// Main assert macro, usage: JPH_ASSERT(condition, message) or JPH_ASSERT(condition)
  21. #define JPH_ASSERT(inExpression, ...) do { if (!(inExpression) && AssertFailedParamHelper(#inExpression, __FILE__, uint(__LINE__), ##__VA_ARGS__, AssertLastParam())) JPH_BREAKPOINT; } while (false)
  22. #define JPH_IF_ENABLE_ASSERTS(...) __VA_ARGS__
  23. #else
  24. #define JPH_ASSERT(...) ((void)0)
  25. #define JPH_IF_ENABLE_ASSERTS(...)
  26. #endif // JPH_ENABLE_ASSERTS
  27. JPH_NAMESPACE_END