diff --git a/src/common/objects/dobject.cpp b/src/common/objects/dobject.cpp index aaf7884bc..c9a0babed 100644 --- a/src/common/objects/dobject.cpp +++ b/src/common/objects/dobject.cpp @@ -333,10 +333,22 @@ void DObject::Destroy () GC::WriteBarrier(this); } -DEFINE_ACTION_FUNCTION(DObject, Destroy) +// This will be here until prediction can be reworked. +// TODO: Fix prediction by serializing instead of using this terrible memcpy method. +bool bPredictionGuard = false; + +static void NativeDestroy(DObject* self) +{ + if (bPredictionGuard && !(self->ObjectFlags & OF_ClientSide) && ((self->ObjectFlags & OF_Networked) || self->IsKindOf(NAME_Thinker))) + DPrintf(DMSG_WARNING, TEXTCOLOR_RED "Destroyed non-client-side Object %s while predicting\n", self->GetClass()->TypeName.GetChars()); + if (!(self->ObjectFlags & OF_EuthanizeMe)) + self->Destroy(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DObject, Destroy, NativeDestroy) { PARAM_SELF_PROLOGUE(DObject); - self->Destroy(); + NativeDestroy(self); return 0; } diff --git a/src/common/objects/dobject.h b/src/common/objects/dobject.h index 6aba45da3..852e0706c 100644 --- a/src/common/objects/dobject.h +++ b/src/common/objects/dobject.h @@ -369,6 +369,8 @@ public: virtual void EnableNetworking(const bool enable); }; +extern bool bPredictionGuard; + // This is the only method aside from calling CreateNew that should be used for creating DObjects // to ensure that the Class pointer is always set. template diff --git a/src/g_levellocals.h b/src/g_levellocals.h index d4945af5c..6975aab5a 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -456,6 +456,8 @@ public: DThinker *CreateThinker(PClass *cls, int statnum = STAT_DEFAULT) { + if (bPredictionGuard) + DPrintf(DMSG_WARNING, TEXTCOLOR_RED "Spawned non-client-side Thinker %s while predicting\n", cls->TypeName.GetChars()); DThinker *thinker = static_cast(cls->CreateNew()); assert(thinker->IsKindOf(RUNTIME_CLASS(DThinker))); thinker->ObjectFlags |= OF_JustSpawned; diff --git a/src/playsim/p_user.cpp b/src/playsim/p_user.cpp index 3ff52b988..8533abf38 100644 --- a/src/playsim/p_user.cpp +++ b/src/playsim/p_user.cpp @@ -1482,6 +1482,10 @@ void P_PredictPlayer (player_t *player) return; } + bPredictionGuard = true; + // Avoid memcpying in bad pointers. + GC::CheckGC(); + FRandom::SaveRNGState(PredictionRNG); // Save original values for restoration later @@ -1713,6 +1717,8 @@ void P_UnPredictPlayer () actInvSel = InvSel; player->inventorytics = inventorytics; + + bPredictionGuard = false; } }