diff options
author | Simon Howard | 2007-09-14 22:20:08 +0000 |
---|---|---|
committer | Simon Howard | 2007-09-14 22:20:08 +0000 |
commit | 5ac7ac324198351603d07f8895a53ec906653ff7 (patch) | |
tree | 7b673bd717981b2fd60ab8a89202b2329756917c /src/p_mobj.c | |
parent | 056415e2d68e261583a6fcfe1df24d5724ef91a8 (diff) | |
download | chocolate-doom-5ac7ac324198351603d07f8895a53ec906653ff7.tar.gz chocolate-doom-5ac7ac324198351603d07f8895a53ec906653ff7.tar.bz2 chocolate-doom-5ac7ac324198351603d07f8895a53ec906653ff7.zip |
Add P_SubstNullMobj, substitute NULL mobjs for a dummy mobj where
mo->target is not checked for NULL.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 971
Diffstat (limited to 'src/p_mobj.c')
-rw-r--r-- | src/p_mobj.c | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/src/p_mobj.c b/src/p_mobj.c index 29dafdec..bb72166d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -922,6 +922,28 @@ void P_CheckMissileSpawn (mobj_t* th) P_ExplodeMissile (th); } +// Certain functions assume that a mobj_t pointer is non-NULL, +// causing a crash in some situations where it is NULL. Vanilla +// Doom did not crash because of the lack of proper memory +// protection. This function substitutes NULL pointers for +// pointers to a dummy mobj, to avoid a crash. + +mobj_t *P_SubstNullMobj(mobj_t *mobj) +{ + if (mobj == NULL) + { + static mobj_t dummy_mobj; + + dummy_mobj.x = 0; + dummy_mobj.y = 0; + dummy_mobj.z = 0; + dummy_mobj.flags = 0; + + mobj = &dummy_mobj; + } + + return mobj; +} // // P_SpawnMissile @@ -935,31 +957,6 @@ P_SpawnMissile mobj_t* th; angle_t an; int dist; - fixed_t dest_x, dest_y, dest_z, dest_flags; - - // fraggle: This prevents against *crashes* when dest == NULL. - // For example, when loading a game saved when a mancubus was - // in the middle of firing, mancubus->target == NULL. SpawnMissile - // then gets called with dest == NULL. - // - // However, this is not the *correct* behavior. At the moment, - // the missile is aimed at 0,0,0. In reality, monsters seem to aim - // somewhere else. - - if (dest) - { - dest_x = dest->x; - dest_y = dest->y; - dest_z = dest->z; - dest_flags = dest->flags; - } - else - { - dest_x = 0; - dest_y = 0; - dest_z = 0; - dest_flags = 0; - } th = P_SpawnMobj (source->x, source->y, @@ -969,10 +966,10 @@ P_SpawnMissile S_StartSound (th, th->info->seesound); th->target = source; // where it came from - an = R_PointToAngle2 (source->x, source->y, dest_x, dest_y); + an = R_PointToAngle2 (source->x, source->y, dest->x, dest->y); // fuzzy player - if (dest_flags & MF_SHADOW) + if (dest->flags & MF_SHADOW) an += (P_Random()-P_Random())<<20; th->angle = an; @@ -980,13 +977,13 @@ P_SpawnMissile th->momx = FixedMul (th->info->speed, finecosine[an]); th->momy = FixedMul (th->info->speed, finesine[an]); - dist = P_AproxDistance (dest_x - source->x, dest_y - source->y); + dist = P_AproxDistance (dest->x - source->x, dest->y - source->y); dist = dist / th->info->speed; if (dist < 1) dist = 1; - th->momz = (dest_z - source->z) / dist; + th->momz = (dest->z - source->z) / dist; P_CheckMissileSpawn (th); return th; |