From e39b23a437e2911edcb2ad5734a6a42b9615a930 Mon Sep 17 00:00:00 2001 From: Cyp Date: Wed, 8 Dec 2010 17:28:44 +0100 Subject: [PATCH] Implement syncDebugFeature, to check that features are also in synch. --- src/feature.c | 20 +++++++++++++++++++- src/feature.h | 3 +++ src/multibot.cpp | 2 ++ src/multigifts.c | 1 + src/objmem.c | 5 +++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/feature.c b/src/feature.c index 9cbab9bb1..0383fa2c2 100644 --- a/src/feature.c +++ b/src/feature.c @@ -29,6 +29,7 @@ #include "lib/gamelib/gtime.h" #include "lib/sound/audio.h" #include "lib/sound/audio_id.h" +#include "lib/netplay/netplay.h" #include "feature.h" #include "map.h" @@ -449,10 +450,25 @@ void featureRelease(FEATURE *psFeature) { } +void _syncDebugFeature(const char *function, FEATURE *psFeature, char ch) +{ + _syncDebug(function, "%c feature%d = p%d;pos(%d,%d,%d),subtype%d,dam%d,bp%d", ch, + psFeature->id, + + psFeature->player, + psFeature->pos.x, psFeature->pos.y, psFeature->pos.z, + psFeature->psStats->subType, + psFeature->psStats->damageable, + psFeature->body + + ); +} /* Update routine for features */ void featureUpdate(FEATURE *psFeat) { + syncDebugFeature(psFeat, '<'); + // if(getRevealStatus()) // { // update the visibility for the feature @@ -468,10 +484,12 @@ void featureUpdate(FEATURE *psFeat) // { destroyFeature(psFeat); // get rid of the now!!! // } - break; + return; default: break; } + + syncDebugFeature(psFeat, '>'); } diff --git a/src/feature.h b/src/feature.h index b694a62ef..f33f6183b 100644 --- a/src/feature.h +++ b/src/feature.h @@ -70,6 +70,9 @@ int32_t featureDamage(FEATURE *psFeature, UDWORD damage, WEAPON_CLASS weaponClas extern void featureInitVars(void); +#define syncDebugFeature(psFeature, ch) _syncDebugFeature(__FUNCTION__, psFeature, ch) +void _syncDebugFeature(const char *function, FEATURE *psFeature, char ch); + #ifdef __cplusplus } #endif //__cplusplus diff --git a/src/multibot.cpp b/src/multibot.cpp index ada88f420..f56974896 100644 --- a/src/multibot.cpp +++ b/src/multibot.cpp @@ -475,6 +475,8 @@ BOOL recvDroid(NETQUEUE queue) orderDroidLoc(psDroid, DORDER_MOVE, initialOrders.moveToX, initialOrders.moveToY, ModeImmediate); cbNewDroid(IdToStruct(initialOrders.factoryId, ANYPLAYER), psDroid); } + + syncDebugDroid(psDroid, '+'); } else { diff --git a/src/multigifts.c b/src/multigifts.c index 14939924f..211ebd6d1 100644 --- a/src/multigifts.c +++ b/src/multigifts.c @@ -722,6 +722,7 @@ void recvMultiPlayerRandomArtifacts(NETQUEUE queue) { pF->id = ref; pF->player = player; + syncDebugFeature(pF, '+'); } else { diff --git a/src/objmem.c b/src/objmem.c index 92a54e287..3626dadea 100644 --- a/src/objmem.c +++ b/src/objmem.c @@ -130,6 +130,11 @@ static void objmemDestroy(BASE_OBJECT *psObj) visRemoveVisibility(psObj); free(psObj->watchedTiles); +#ifdef DEBUG + psObj->type = (OBJECT_TYPE)(psObj->type + 1000000000); // Hopefully this will trigger an assert if someone uses the freed object. + psObj->player += 1000000000; // Hopefully this will trigger an assert and/or crash if someone uses the freed object. + psObj->psNext = psObj; // Hopefully this will trigger an infinite loop if someone uses the freed object. +#endif //DEBUG free(psObj); debug(LOG_MEMORY, "BASE_OBJECT* 0x%p is freed.", psObj); }