Skip to content

Commit

Permalink
- Duke/RR: added null checks to all spawn() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Nov 21, 2021
1 parent 3bca024 commit c841f94
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 250 deletions.
55 changes: 34 additions & 21 deletions source/games/duke/src/actors.cpp
Expand Up @@ -554,7 +554,7 @@ void movefx(void)
if (spri->extra == 66)
{
auto j = spawn(act, spri->hitag);
if (isRRRA())
if (isRRRA() && j)
{
respawn_rrra(act, j);
}
Expand Down Expand Up @@ -870,7 +870,7 @@ void moveflammable(DDukeActor* actor, int tire, int box, int pool)
{
spri->cstat = 0;
auto spawned = spawn(actor, pool);
spawned->s->shade = 127;
if (spawned) spawned->s->shade = 127;
}
else
{
Expand Down Expand Up @@ -1393,6 +1393,7 @@ void rpgexplode(DDukeActor *actor, int hit, const vec3_t &pos, int EXPLOSION2, i
{
auto s = actor->s;
auto explosion = spawn(actor, EXPLOSION2);
if (!explosion) return;
explosion->s->pos = pos;

if (s->xrepeat < 10)
Expand Down Expand Up @@ -1596,12 +1597,15 @@ void forcesphere(DDukeActor* actor, int forcesphere)
for (int j = 0; j < 2048; j += 128)
{
auto k = spawn(actor, forcesphere);
k->s->cstat = 257 + 128;
k->s->clipdist = 64;
k->s->ang = j;
k->s->zvel = bsin(l, -5);
k->s->xvel = bcos(l, -9);
k->SetOwner(actor);
if (k)
{
k->s->cstat = 257 + 128;
k->s->clipdist = 64;
k->s->ang = j;
k->s->zvel = bsin(l, -5);
k->s->xvel = bcos(l, -9);
k->SetOwner(actor);
}
}
}

Expand Down Expand Up @@ -2584,9 +2588,12 @@ void scrap(DDukeActor* actor, int SCRAP1, int SCRAP6)
if (s->picnum == SCRAP1 && s->yvel > 0)
{
auto spawned = spawn(actor, s->yvel);
setsprite(spawned, s->pos);
getglobalz(spawned);
spawned->s->hitag = spawned->s->lotag = 0;
if (spawned)
{
setsprite(spawned, s->pos);
getglobalz(spawned);
spawned->s->hitag = spawned->s->lotag = 0;
}
}
deletesprite(actor);
}
Expand Down Expand Up @@ -4664,11 +4671,14 @@ void handle_se35(DDukeActor *actor, int SMALLSMOKE, int EXPLOSION2)
{
s->ang += krand() & 511;
auto spawned = spawn(actor, SMALLSMOKE);
spawned->s->xvel = 96 + (krand() & 127);
ssp(spawned, CLIPMASK0);
setsprite(spawned, spawned->s->pos);
if (rnd(16))
spawn(actor, EXPLOSION2);
if (spawned)
{
spawned->s->xvel = 96 + (krand() & 127);
ssp(spawned, CLIPMASK0);
setsprite(spawned, spawned->s->pos);
if (rnd(16))
spawn(actor, EXPLOSION2);
}
}

switch (t[0])
Expand Down Expand Up @@ -4754,11 +4764,14 @@ void handle_se130(DDukeActor *actor, int countmax, int EXPLOSION2)
if (rnd(64))
{
auto k = spawn(actor, EXPLOSION2);
k->s->xrepeat = k->s->yrepeat = 2 + (krand() & 7);
k->s->z = sc->floorz - (krand() % x);
k->s->ang += 256 - (krand() % 511);
k->s->xvel = krand() & 127;
ssp(k, CLIPMASK0);
if (k)
{
k->s->xrepeat = k->s->yrepeat = 2 + (krand() & 7);
k->s->z = sc->floorz - (krand() % x);
k->s->ang += 256 - (krand() % 511);
k->s->xvel = krand() & 127;
ssp(k, CLIPMASK0);
}
}
}

Expand Down
152 changes: 86 additions & 66 deletions source/games/duke/src/actors_d.cpp
Expand Up @@ -1057,9 +1057,12 @@ static void movetripbomb(DDukeActor *actor)
fi.hitradius(actor, gs.tripbombblastradius, x >> 2, x >> 1, x - (x >> 2), x);

auto spawned = spawn(actor, EXPLOSION2);
spawned->s->ang = s->ang;
spawned->s->xvel = 348;
ssp(spawned, CLIPMASK0);
if (spawned)
{
spawned->s->ang = s->ang;
spawned->s->xvel = 348;
ssp(spawned, CLIPMASK0);
}

DukeStatIterator it(STAT_MISC);
while (auto a1 = it.Next())
Expand Down Expand Up @@ -1121,29 +1124,31 @@ static void movetripbomb(DDukeActor *actor)
while (x > 0)
{
auto spawned = spawn(actor, LASERLINE);
setsprite(spawned, spawned->s->pos);
spawned->s->hitag = s->hitag;
spawned->temp_data[1] = spawned->s->z;

if (x < 1024)
if (spawned)
{
spawned->s->xrepeat = x >> 5;
break;
}
x -= 1024;
setsprite(spawned, spawned->s->pos);
spawned->s->hitag = s->hitag;
spawned->temp_data[1] = spawned->s->z;

s->x += bcos(actor->temp_data[5], -4);
s->y += bsin(actor->temp_data[5], -4);
updatesectorneighbor(s->x, s->y, &curSectNum, 1024, 2048);
if (x < 1024)
{
spawned->s->xrepeat = x >> 5;
break;
}
x -= 1024;

if (curSectNum == -1)
break;
s->x += bcos(actor->temp_data[5], -4);
s->y += bsin(actor->temp_data[5], -4);
updatesectorneighbor(s->x, s->y, &curSectNum, 1024, 2048);

changeactorsect(actor, curSectNum);
if (curSectNum == -1)
break;

// this is a hack to work around the LASERLINE sprite's art tile offset
changeactorsect(spawned, curSectNum);
changeactorsect(actor, curSectNum);

// this is a hack to work around the LASERLINE sprite's art tile offset
changeactorsect(spawned, curSectNum);
}
}
}

Expand Down Expand Up @@ -1543,33 +1548,36 @@ static bool movefireball(DDukeActor* actor)
// This still needs work- it stores an actor reference in a general purpose integer field.
int trail = actor->temp_data[1];
auto ball = spawn(actor, FIREBALL);
auto spr = ball->s;
actor->temp_data[1] = ball->GetSpriteIndex();

spr->xvel = s->xvel;
spr->yvel = s->yvel;
spr->zvel = s->zvel;
if (actor->temp_data[0] > 1)
if (ball)
{
FireProj* proj = fire.CheckKey(trail);
if (proj != nullptr)
auto spr = ball->s;
actor->temp_data[1] = ball->GetSpriteIndex();

spr->xvel = s->xvel;
spr->yvel = s->yvel;
spr->zvel = s->zvel;
if (actor->temp_data[0] > 1)
{
spr->x = proj->x;
spr->y = proj->y;
spr->z = proj->z;
spr->xvel = proj->xv;
spr->yvel = proj->yv;
spr->zvel = proj->zv;
FireProj* proj = fire.CheckKey(trail);
if (proj != nullptr)
{
spr->x = proj->x;
spr->y = proj->y;
spr->z = proj->z;
spr->xvel = proj->xv;
spr->yvel = proj->yv;
spr->zvel = proj->zv;
}
}
}
spr->yrepeat = spr->xrepeat = (uint8_t)(s->xrepeat * siz);
spr->cstat = s->cstat;
spr->extra = 0;
spr->yrepeat = spr->xrepeat = (uint8_t)(s->xrepeat * siz);
spr->cstat = s->cstat;
spr->extra = 0;

FireProj proj = { spr->x, spr->y, spr->z, spr->xvel, spr->yvel, spr->zvel };

fire.Insert(ball->GetSpriteIndex(), proj);
changeactorstat(ball, STAT_PROJECTILE);
FireProj proj = { spr->x, spr->y, spr->z, spr->xvel, spr->yvel, spr->zvel };

fire.Insert(ball->GetSpriteIndex(), proj);
changeactorstat(ball, STAT_PROJECTILE);
}
}
actor->temp_data[0]++;
}
Expand All @@ -1591,9 +1599,12 @@ static bool weaponhitsprite(DDukeActor* proj, DDukeActor *targ, bool fireball)
if (badguy(targ) || targ->s->picnum == APLAYER)
{
auto spawned = spawn(targ, TRANSPORTERSTAR);
spawned->s->pal = 1;
spawned->s->xrepeat = 32;
spawned->s->yrepeat = 32;
if (spawned)
{
spawned->s->pal = 1;
spawned->s->xrepeat = 32;
spawned->s->yrepeat = 32;
}

deletesprite(proj);
return true;
Expand Down Expand Up @@ -1705,9 +1716,12 @@ static bool weaponhitsector(DDukeActor* proj, const vec3_t& oldpos, bool firebal
else if (fireball)
{
auto spawned = spawn(proj, LAVAPOOL);
spawned->SetOwner(proj);
spawned->SetHitOwner(proj);
spawned->s->yvel = s->yvel;
if (spawned)
{
spawned->SetOwner(proj);
spawned->SetHitOwner(proj);
spawned->s->yvel = s->yvel;
}
deletesprite(proj);
return true;
}
Expand Down Expand Up @@ -1762,7 +1776,7 @@ static void weaponcommon_d(DDukeActor* proj)
if (proj->picnum != BOSS2 && s->xrepeat >= 10 && s->sector()->lotag != 2)
{
auto spawned = spawn(proj, SMALLSMOKE);
spawned->s->z += (1 << 8);
if (spawned) spawned->s->z += (1 << 8);
}
break;

Expand Down Expand Up @@ -1865,19 +1879,22 @@ static void weaponcommon_d(DDukeActor* proj)
else if (s->picnum != COOLEXPLOSION1 && s->picnum != FREEZEBLAST && s->picnum != FIRELASER && (!isWorldTour() || s->picnum != FIREBALL))
{
auto k = spawn(proj, EXPLOSION2);
k->s->xrepeat = k->s->yrepeat = s->xrepeat >> 1;
if (coll.type == kHitSector)
if (k)
{
if (s->zvel < 0)
k->s->xrepeat = k->s->yrepeat = s->xrepeat >> 1;
if (coll.type == kHitSector)
{
k->s->cstat |= 8; k->s->z += (72 << 8);
if (s->zvel < 0)
{
k->s->cstat |= 8; k->s->z += (72 << 8);
}
}
}
}
if (fireball)
{
auto spawned = spawn(proj, EXPLOSION2);
spawned->s->xrepeat = spawned->s->yrepeat = (short)(s->xrepeat >> 1);
if (spawned) spawned->s->xrepeat = spawned->s->yrepeat = (short)(s->xrepeat >> 1);
}
}
if (s->picnum != COOLEXPLOSION1)
Expand Down Expand Up @@ -1931,9 +1948,12 @@ void moveweapons_d(void)
if (act->s->yvel < 1 || act->s->extra < 2 || (act->s->xvel|act->s->zvel) == 0)
{
auto spawned = spawn(act,TRANSPORTERSTAR);
spawned->s->pal = 1;
spawned->s->xrepeat = 32;
spawned->s->yrepeat = 32;
if (spawned)
{
spawned->s->pal = 1;
spawned->s->xrepeat = 32;
spawned->s->yrepeat = 32;
}
deletesprite(act);
continue;
}
Expand Down Expand Up @@ -2039,7 +2059,7 @@ void movetransports_d(void)
if (spr->pal == 0)
{
auto k = spawn(Owner, TRANSPORTERBEAM);
S_PlayActorSound(TELEPORTER, k);
if (k) S_PlayActorSound(TELEPORTER, k);
}

break;
Expand Down Expand Up @@ -2124,7 +2144,7 @@ void movetransports_d(void)
for (int l = 0; l < 9; l++)
{
auto q = spawn(ps[p].GetActor(), WATERBUBBLE);
q->s->z += krand() & 16383;
if (q) q->s->z += krand() & 16383;
}
}
}
Expand Down Expand Up @@ -2206,7 +2226,7 @@ void movetransports_d(void)
if (sectlotag > 0)
{
auto k = spawn(act2, WATERSPLASH2);
if (sectlotag == 1 && spr2->statnum == 4)
if (k && sectlotag == 1 && spr2->statnum == 4)
{
k->s->xvel = spr2->xvel >> 1;
k->s->ang = spr2->ang;
Expand All @@ -2231,10 +2251,10 @@ void movetransports_d(void)
if (spr->pal == 0)
{
auto k = spawn(act, TRANSPORTERBEAM);
S_PlayActorSound(TELEPORTER, k);
if (k) S_PlayActorSound(TELEPORTER, k);

k = spawn(Owner, TRANSPORTERBEAM);
S_PlayActorSound(TELEPORTER, k);
if (k) S_PlayActorSound(TELEPORTER, k);
}

if (Owner && Owner->GetOwner() == Owner)
Expand Down Expand Up @@ -2405,7 +2425,7 @@ static void greenslime(DDukeActor *actor)
if ((krand() & 255) < 32)
{
auto j = spawn(actor, BLOODPOOL);
j->s->pal = 0;
if (j) j->s->pal = 0;
}
ps[p].actors_killed++;
t[0] = -3;
Expand Down Expand Up @@ -2506,13 +2526,13 @@ static void greenslime(DDukeActor *actor)
if ((krand() & 255) < 32)
{
auto j = spawn(actor, BLOODPOOL);
j->s->pal = 0;
if (j) j->s->pal = 0;
}

for (x = 0; x < 8; x++)
{
auto j = EGS(s->sector(), s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), actor, 5);
j->s->pal = 6;
if (j) j->s->pal = 6;
}
t[0] = -3;
deletesprite(actor);
Expand Down

0 comments on commit c841f94

Please sign in to comment.