- fixed several Destroy methods which blanketly assumed that the object's pointers were valid to use without checks.

This is not the case if deserialization prematurely aborts. The entire object may be invalid if something in the deserializer I_Error's out.
This commit is contained in:
Christoph Oelckers 2016-09-23 08:49:30 +02:00
parent 657140f985
commit cad2be46ac
4 changed files with 57 additions and 34 deletions

View file

@ -116,13 +116,16 @@ void DBaseDecal::Destroy ()
void DBaseDecal::Remove ()
{
if (WallPrev == nullptr) Side->AttachedDecals = WallNext;
if (WallPrev == nullptr)
{
if (Side != nullptr) Side->AttachedDecals = WallNext;
}
else WallPrev->WallNext = WallNext;
if (WallNext != nullptr) WallNext->WallPrev = WallPrev;
WallPrev = NULL;
WallNext = NULL;
WallPrev = nullptr;
WallNext = nullptr;
}
void DBaseDecal::Serialize(FSerializer &arc)

View file

@ -49,23 +49,26 @@ bool ASectorAction::IsActivatedByUse() const
void ASectorAction::Destroy ()
{
// Remove ourself from this sector's list of actions
AActor *probe = Sector->SecActTarget;
union
if (Sector != nullptr)
{
AActor **act;
ASectorAction **secact;
} prev;
prev.secact = &Sector->SecActTarget;
// Remove ourself from this sector's list of actions
AActor *probe = Sector->SecActTarget;
union
{
AActor **act;
ASectorAction **secact;
} prev;
prev.secact = &Sector->SecActTarget;
while (probe && probe != this)
{
prev.act = &probe->tracer;
probe = probe->tracer;
}
if (probe != NULL)
{
*prev.act = probe->tracer;
while (probe && probe != this)
{
prev.act = &probe->tracer;
probe = probe->tracer;
}
if (probe != nullptr)
{
*prev.act = probe->tracer;
}
}
Super::Destroy ();

View file

@ -170,7 +170,10 @@ void ASectorSilencer::BeginPlay ()
void ASectorSilencer::Destroy ()
{
Sector->Flags &= ~SECF_SILENT;
if (Sector != nullptr)
{
Sector->Flags &= ~SECF_SILENT;
}
Super::Destroy ();
}

View file

@ -418,15 +418,18 @@ DSectorPlaneInterpolation::DSectorPlaneInterpolation(sector_t *_sector, bool _pl
void DSectorPlaneInterpolation::Destroy()
{
if (ceiling)
if (sector != nullptr)
{
sector->interpolations[sector_t::CeilingMove] = NULL;
if (ceiling)
{
sector->interpolations[sector_t::CeilingMove] = nullptr;
}
else
{
sector->interpolations[sector_t::FloorMove] = nullptr;
}
sector = nullptr;
}
else
{
sector->interpolations[sector_t::FloorMove] = NULL;
}
for(unsigned i=0; i<attached.Size(); i++)
{
attached[i]->DelRef();
@ -593,13 +596,17 @@ DSectorScrollInterpolation::DSectorScrollInterpolation(sector_t *_sector, bool _
void DSectorScrollInterpolation::Destroy()
{
if (ceiling)
if (sector != nullptr)
{
sector->interpolations[sector_t::CeilingScroll] = NULL;
}
else
{
sector->interpolations[sector_t::FloorScroll] = NULL;
if (ceiling)
{
sector->interpolations[sector_t::CeilingScroll] = nullptr;
}
else
{
sector->interpolations[sector_t::FloorScroll] = nullptr;
}
sector = nullptr;
}
Super::Destroy();
}
@ -694,7 +701,11 @@ DWallScrollInterpolation::DWallScrollInterpolation(side_t *_side, int _part)
void DWallScrollInterpolation::Destroy()
{
side->textures[part].interpolation = NULL;
if (side != nullptr)
{
side->textures[part].interpolation = nullptr;
side = nullptr;
}
Super::Destroy();
}
@ -788,7 +799,10 @@ DPolyobjInterpolation::DPolyobjInterpolation(FPolyObj *po)
void DPolyobjInterpolation::Destroy()
{
poly->interpolation = NULL;
if (poly != nullptr)
{
poly->interpolation = nullptr;
}
Super::Destroy();
}