From a6e144ea72be5892490ecfe7b6137888f04b39dc Mon Sep 17 00:00:00 2001 From: def Date: Fri, 2 Jun 2017 20:12:20 +0200 Subject: [PATCH] Let's not crash the client and server on dbg_assert --- src/base/system.c | 4 ++-- src/base/system.h | 18 +++++++++++++----- src/engine/shared/uuid_manager.cpp | 3 +-- src/game/server/gamecontext.cpp | 2 -- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index df1a51fef..a68795412 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -97,11 +97,11 @@ void dbg_assert_imp(const char *filename, int line, int test, const char *msg) if(!test) { dbg_msg("assert", "%s(%d): %s", filename, line, msg); - dbg_break(); + dbg_break_imp(); } } -void dbg_break() +void dbg_break_imp() { *((volatile unsigned*)0) = 0x0; } diff --git a/src/base/system.h b/src/base/system.h index 1332e2877..e49fd2c80 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -26,13 +26,16 @@ extern "C" { msg - Message that should be printed if the test fails. Remarks: - Does nothing in release version of the library. + Does nothing in release version See Also: */ -void dbg_assert(int test, const char *msg); +#ifdef CONF_DEBUG #define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg) +#else +#define dbg_assert(test,msg) +#endif void dbg_assert_imp(const char *filename, int line, int test, const char *msg); @@ -47,12 +50,17 @@ void dbg_assert_imp(const char *filename, int line, int test, const char *msg); Breaks into the debugger. Remarks: - Does nothing in release version of the library. + Does nothing in release version See Also: */ -void dbg_break(); +#ifdef CONF_DEBUG +#define dbg_break() dbg_break_imp() +#else +#define dbg_break() +#endif +void dbg_break_imp(); /* Function: dbg_msg @@ -64,7 +72,7 @@ void dbg_break(); fmt - A printf styled format string. Remarks: - Does nothing in release version of the library. + Also works in release version See Also: diff --git a/src/engine/shared/uuid_manager.cpp b/src/engine/shared/uuid_manager.cpp index 3a8805e75..6f6518d52 100644 --- a/src/engine/shared/uuid_manager.cpp +++ b/src/engine/shared/uuid_manager.cpp @@ -66,8 +66,7 @@ static int GetID(int Index) void CUuidManager::RegisterName(int ID, const char *pName) { - int Index = GetIndex(ID); - dbg_assert(Index == m_aNames.size(), "names must be registered with increasing ID"); + dbg_assert(GetIndex(ID) == m_aNames.size(), "names must be registered with increasing ID"); CName Name; Name.m_pName = pName; Name.m_Uuid = CalculateUuid(pName); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 0767f87e0..26cefa655 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -3032,8 +3032,6 @@ void CGameContext::ResetTuning() bool CheckClientID2(int ClientID) { - dbg_assert(ClientID >= 0 || ClientID < MAX_CLIENTS, - "The Client ID is wrong"); if (ClientID < 0 || ClientID >= MAX_CLIENTS) return false; return true;