Skip to content

Commit

Permalink
Don't include backtraces in syncDebug CRCs.
Browse files Browse the repository at this point in the history
This should allow using syncDebugBacktrace() without causing a desynch if some clients don't support them or print them differently.
  • Loading branch information
Cyp committed Dec 8, 2010
1 parent 707e7d4 commit f5893a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/netplay/netplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -3000,8 +3000,10 @@ void _syncDebug(const char *function, const char *str, ...)
}
}

void syncDebugBacktrace(void)
void _syncDebugBacktrace(const char *function)
{
uint32_t backupCrc = syncDebugCrcs[syncDebugNext]; // Ignore CRC changes from _syncDebug(), since identical backtraces can be printed differently.

#ifdef WZ_OS_LINUX
void *btv[20];
unsigned num = backtrace(btv, sizeof(btv)/sizeof(*btv));
Expand All @@ -3013,8 +3015,11 @@ void syncDebugBacktrace(void)
}
free(btc);
#else
_syncDebug("BT", "Sorry, syncDebugBacktrace() not implemented on your system.");
_syncDebug("BT", "Sorry, syncDebugBacktrace() not implemented on your system. Called from %s.", function);
#endif

// Use CRC of something platform-independent, to avoid false positive desynchs.
syncDebugCrcs[syncDebugNext] = crcSum(backupCrc, function, strlen(function) + 1);
}

static void clearSyncDebugNext(void)
Expand Down
3 changes: 2 additions & 1 deletion lib/netplay/netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ const char *messageTypeToString(unsigned messageType);
#define syncDebug(...) do { _syncDebug(__FUNCTION__, __VA_ARGS__); } while(0)
void _syncDebug(const char *function, const char *str, ...)
WZ_DECL_FORMAT(printf, 2, 3);
void syncDebugBacktrace(void); ///< Adds a backtrace to syncDebug. (Expect lots of false positives, if all clients aren't using the exact same binaries.)
#define syncDebugBacktrace() do { _syncDebugBacktrace(__FUNCTION__); } while(0)
void _syncDebugBacktrace(const char *function); ///< Adds a backtrace to syncDebug, if the platform supports it. Can be a bit slow, don't call way too often, unless desperate.

void resetSyncDebug(void); ///< Resets the syncDebug, so syncDebug from a previous game doesn't cause a spurious desynch dump.
uint32_t nextDebugSync(void); ///< Returns a CRC corresponding to all syncDebug() calls since the last nextDebugSync() or resetSyncDebug() call.
Expand Down

0 comments on commit f5893a7

Please sign in to comment.