- 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 () void DBaseDecal::Remove ()
{ {
if (WallPrev == nullptr) Side->AttachedDecals = WallNext; if (WallPrev == nullptr)
{
if (Side != nullptr) Side->AttachedDecals = WallNext;
}
else WallPrev->WallNext = WallNext; else WallPrev->WallNext = WallNext;
if (WallNext != nullptr) WallNext->WallPrev = WallPrev; if (WallNext != nullptr) WallNext->WallPrev = WallPrev;
WallPrev = NULL; WallPrev = nullptr;
WallNext = NULL; WallNext = nullptr;
} }
void DBaseDecal::Serialize(FSerializer &arc) void DBaseDecal::Serialize(FSerializer &arc)

View file

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

View file

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

View file

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