From d8ae277d6bc59894ee3db414307854a1c803d849 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 12 Dec 2015 18:05:14 +1100 Subject: [PATCH] assert_once --- qcsrc/client/main.qc | 2 +- qcsrc/client/miscfunctions.qc | 2 +- qcsrc/lib/log.qh | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 576b2485c..79723cc3c 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -167,7 +167,7 @@ void Shutdown() .float has_team; float SetTeam(entity o, int Team) { - assert(Team); + assert_once(Team); entity tm; if(teamplay) { diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index d488dd63b..b7962d52d 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -79,7 +79,7 @@ void MoveToLast(entity e) float RegisterTeam(entity Team) { - assert(Team.team, eprint(Team)); + assert_once(Team.team, eprint(Team)); entity tm; AuditLists(); for(tm = teams.sort_next; tm; tm = tm.sort_next) diff --git a/qcsrc/lib/log.qh b/qcsrc/lib/log.qh index 60f8d103d..ab94e571b 100644 --- a/qcsrc/lib/log.qh +++ b/qcsrc/lib/log.qh @@ -12,6 +12,15 @@ } MACRO_END #define assert(expr, ...) _assert(LOG_SEVERE, expr, __VA_ARGS__) +#define assert_once(expr, ...) \ + MACRO_BEGIN { \ + static bool __once; \ + if (!__once) \ + { \ + assert(expr, __VA_ARGS__); \ + __once = true; \ + } \ + } MACRO_END #define demand(expr, ...) _assert(LOG_FATAL, expr, __VA_ARGS__) #define _assert(f, expr, then) \ MACRO_BEGIN \ -- 2.39.2