Skip to content

Commit

Permalink
Don't remove custom assert failure registering code when disabling as…
Browse files Browse the repository at this point in the history
…sertions

Otherwise, when disabling assertions, client code that calls these custom assertion failure callback registration functions will break.
  • Loading branch information
grahamboree committed Dec 31, 2024
1 parent 6bc7953 commit 3ca46fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
28 changes: 12 additions & 16 deletions Recast/Include/RecastAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,31 @@
#ifndef RECASTASSERT_H
#define RECASTASSERT_H

#ifdef RC_DISABLE_ASSERTS

// From https://web.archive.org/web/20210117002833/http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/
# define rcAssert(x) do { (void)sizeof(x); } while ((void)(__LINE__==-1), false)

#else

/// An assertion failure function.
// @param[in] expression asserted expression.
// @param[in] file Filename of the failed assertion.
// @param[in] line Line number of the failed assertion.
/// @see rcAssertFailSetCustom
/// An assertion failure callback function.
/// @param[in] expression Asserted expression.
/// @param[in] file Filename of the failed assertion.
/// @param[in] line Line number of the failed assertion.
/// @see rcAssertFailSetCustom
typedef void (rcAssertFailFunc)(const char* expression, const char* file, int line);

/// Sets the base custom assertion failure function to be used by Recast.
/// @param[in] assertFailFunc The function to be used in case of failure of #dtAssert
/// Sets the base custom assertion failure callback function to be used by Recast.
/// @param[in] assertFailFunc The function to be used in case of failure of #dtAssert
void rcAssertFailSetCustom(rcAssertFailFunc* assertFailFunc);

/// Gets the base custom assertion failure function to be used by Recast.
rcAssertFailFunc* rcAssertFailGetCustom();

#ifdef RC_DISABLE_ASSERTS
// From https://web.archive.org/web/20210117002833/http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/
# define rcAssert(x) do { (void)sizeof(x); } while ((void)(__LINE__==-1), false)
#else
# include <assert.h>
# define rcAssert(expression) \
{ \
rcAssertFailFunc* failFunc = rcAssertFailGetCustom(); \
if (failFunc == NULL) { assert(expression); } \
else if (!(expression)) { (*failFunc)(#expression, __FILE__, __LINE__); } \
}

#endif
#endif // !defined(RC_DISABLE_ASSERTS)

#endif // RECASTASSERT_H
6 changes: 1 addition & 5 deletions Recast/Source/RecastAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#include "RecastAssert.h"

#ifndef RC_DISABLE_ASSERTS

static rcAssertFailFunc* sRecastAssertFailFunc = 0;

void rcAssertFailSetCustom(rcAssertFailFunc* assertFailFunc)
Expand All @@ -30,6 +28,4 @@ void rcAssertFailSetCustom(rcAssertFailFunc* assertFailFunc)
rcAssertFailFunc* rcAssertFailGetCustom()
{
return sRecastAssertFailFunc;
}

#endif
}

0 comments on commit 3ca46fa

Please sign in to comment.