summaryrefslogtreecommitdiff
path: root/src/p_mobj.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/p_mobj.c')
-rw-r--r--src/p_mobj.c55
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;