From 2949361c824754a8c238c8de559a96b78400ef72 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 19 Nov 2021 12:32:12 +0100 Subject: [PATCH] - Duke/RR: added null checks to all spawn() calls --- source/games/duke/src/actors.cpp | 55 ++++++---- source/games/duke/src/actors_d.cpp | 164 ++++++++++++++++------------ source/games/duke/src/actors_r.cpp | 85 ++++++++------ source/games/duke/src/bowling.cpp | 19 ++-- source/games/duke/src/ccmds.cpp | 19 ++-- source/games/duke/src/cheats.cpp | 9 +- source/games/duke/src/player.cpp | 32 +++--- source/games/duke/src/player_d.cpp | 95 +++++++++------- source/games/duke/src/player_r.cpp | 123 +++++++++++++-------- source/games/duke/src/player_w.cpp | 1 + source/games/duke/src/sectors_d.cpp | 24 ++-- source/games/duke/src/sectors_r.cpp | 19 ++-- 12 files changed, 389 insertions(+), 256 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 4a6c8c747..29367ad79 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -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); } @@ -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 { @@ -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) @@ -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); + } } } @@ -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); } @@ -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]) @@ -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); + } } } diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 7352a4e4f..c5ce345eb 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -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()) @@ -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; + setsprite(spawned, spawned->s->pos); + spawned->s->hitag = s->hitag; + spawned->temp_data[1] = spawned->s->z; + + if (x < 1024) + { + spawned->s->xrepeat = x >> 5; + break; + } + x -= 1024; + + 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 (curSectNum == -1) + break; + + changeactorsect(actor, curSectNum); + + // this is a hack to work around the LASERLINE sprite's art tile offset + changeactorsect(spawned, curSectNum); } - x -= 1024; - - 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 (curSectNum == -1) - break; - - changeactorsect(actor, curSectNum); - - // this is a hack to work around the LASERLINE sprite's art tile offset - changeactorsect(spawned, curSectNum); - } } @@ -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) - { - 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; + auto spr = ball->s; + actor->temp_data[1] = ball->GetSpriteIndex(); - FireProj proj = { spr->x, spr->y, spr->z, spr->xvel, spr->yvel, spr->zvel }; - - fire.Insert(ball->GetSpriteIndex(), proj); - changeactorstat(ball, STAT_PROJECTILE); + spr->xvel = s->xvel; + spr->yvel = s->yvel; + spr->zvel = s->zvel; + if (actor->temp_data[0] > 1) + { + 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; + + 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]++; } @@ -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; @@ -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; } @@ -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; @@ -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) @@ -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; } @@ -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; @@ -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; } } } @@ -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; @@ -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) @@ -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; @@ -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); diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 37cf53342..ce715ca60 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1087,7 +1087,7 @@ static void chickenarrow(DDukeActor* actor) if (actor->picnum != BOSS2 && s->xrepeat >= 10 && s->sector()->lotag != 2) { auto spawned = spawn(actor, SMALLSMOKE); - spawned->s->z += (1 << 8); + if (spawned) spawned->s->z += (1 << 8); if ((krand() & 15) == 2) { spawn(actor, MONEY); @@ -1151,9 +1151,12 @@ static bool weaponhitsprite(DDukeActor *proj, DDukeActor *targ, const vec3_t &ol if (badguy(targ) || targ->s->picnum == APLAYER) { auto star = spawn(proj, TRANSPORTERSTAR); - star->s->pal = 1; - star->s->xrepeat = 32; - star->s->yrepeat = 32; + if (star) + { + star->s->pal = 1; + star->s->xrepeat = 32; + star->s->yrepeat = 32; + } deletesprite(proj); return true; @@ -1258,11 +1261,14 @@ static bool weaponhitwall(DDukeActor *proj, walltype* wal, const vec3_t& oldpos) if (!isRRRA() || !Owner || (Owner->s->picnum != CHEER && Owner->s->picnum != CHEERSTAYPUT)) { auto j = spawn(proj, CIRCLESTUCK); - j->s->xrepeat = 8; - j->s->yrepeat = 8; - j->s->cstat = 16; - j->s->ang = (j->s->ang + 512) & 2047; - j->s->clipdist = MulScale(s->xrepeat, tileWidth(s->picnum), 7); + if (j) + { + j->s->xrepeat = 8; + j->s->yrepeat = 8; + j->s->cstat = 16; + j->s->ang = (j->s->ang + 512) & 2047; + j->s->clipdist = MulScale(s->xrepeat, tileWidth(s->picnum), 7); + } } deletesprite(proj); return true; @@ -1465,13 +1471,16 @@ static void weaponcommon_r(DDukeActor *proj) else if (s->picnum != FREEZEBLAST && s->picnum != FIRELASER && s->picnum != SHRINKSPARK) { auto k = spawn(proj, 1441); - 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); + } } } } @@ -1514,9 +1523,12 @@ void moveweapons_r(void) if (proj->s->yvel < 1 || proj->s->extra < 2 || (proj->s->xvel | proj->s->zvel) == 0) { auto star = spawn(proj, TRANSPORTERSTAR); - star->s->pal = 1; - star->s->xrepeat = 32; - star->s->yrepeat = 32; + if (star) + { + star->s->pal = 1; + star->s->xrepeat = 32; + star->s->yrepeat = 32; + } deletesprite(proj); continue; } @@ -1624,7 +1636,7 @@ void movetransports_r(void) ps[p].cursectnum = spr2->sectnum; auto beam = spawn(Owner, TRANSPORTERBEAM); - S_PlayActorSound(TELEPORTER, beam); + if (beam) S_PlayActorSound(TELEPORTER, beam); break; } @@ -1817,7 +1829,7 @@ void movetransports_r(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; @@ -1840,10 +1852,10 @@ void movetransports_r(void) spr2->backupang(); auto beam = spawn(act, TRANSPORTERBEAM); - S_PlayActorSound(TELEPORTER, beam); + if (beam) S_PlayActorSound(TELEPORTER, beam); beam = spawn(Owner, TRANSPORTERBEAM); - S_PlayActorSound(TELEPORTER, beam); + if (beam) S_PlayActorSound(TELEPORTER, beam); if (Owner->GetOwner() != Owner) { @@ -2379,7 +2391,7 @@ void rr_specialstats() { auto j = spawn(act, RRTILE3132); s->lotag = 96; - if (!isRRRA()) S_PlayActorSound(472, j); + if (j && !isRRRA()) S_PlayActorSound(472, j); } break; case RRTILE289: @@ -2772,9 +2784,12 @@ static int henstand(DDukeActor *actor) { auto ns = spawn(hitact, HENSTAND); deletesprite(hitact); - ns->s->xvel = 32; - ns->s->lotag = 40; - ns->s->ang = s->ang; + if (ns) + { + ns->s->xvel = 32; + ns->s->lotag = 40; + ns->s->ang = s->ang; + } } } } @@ -2948,7 +2963,7 @@ void moveactors_r(void) if (sectp->lotag == 1) { auto j = spawn(act, WATERSPLASH2); - j->s->z = j->getSector()->floorz; + if (j) j->s->z = j->getSector()->floorz; } deletesprite(act); continue; @@ -3358,8 +3373,11 @@ void handle_se06_r(DDukeActor *actor) { hulkspawn--; auto ns = spawn(actor, HULK); - ns->s->z = ns->getSector()->ceilingz; - ns->s->pal = 33; + if (ns) + { + ns->s->z = ns->getSector()->ceilingz; + ns->s->pal = 33; + } if (!hulkspawn) { ns = EGS(s->sector(), s->x, s->y, s->sector()->ceilingz + 119428, 3677, -8, 16, 16, 0, 0, 0, actor, 5); @@ -3371,9 +3389,12 @@ void handle_se06_r(DDukeActor *actor) ns->s->yrepeat = 255; } ns = spawn(actor, 296); - ns->s->cstat = 0; - ns->s->cstat |= 32768; - ns->s->z = s->sector()->floorz - 6144; + if (ns) + { + ns->s->cstat = 0; + ns->s->cstat |= 32768; + ns->s->z = s->sector()->floorz - 6144; + } deletesprite(actor); return; } @@ -3412,7 +3433,7 @@ void handle_se06_r(DDukeActor *actor) } else pn = UFO1_RRRA; auto ns = spawn(actor, pn); - ns->s->z = ns->getSector()->ceilingz; + if (ns) ns->s->z = ns->getSector()->ceilingz; } } } diff --git a/source/games/duke/src/bowling.cpp b/source/games/duke/src/bowling.cpp index 0ce463c6c..dc1820298 100644 --- a/source/games/duke/src/bowling.cpp +++ b/source/games/duke/src/bowling.cpp @@ -179,16 +179,19 @@ void resetpins(sectortype* sect) if (a2->s->picnum == 283) { auto spawned = spawn(a2, BOWLINGPIN); - spawned->s->lotag = a2->s->lotag; - if (spawned->s->lotag == 3 || spawned->s->lotag == 5) + if (spawned) { - spawned->s->clipdist = (1 + (krand() % 1)) * 16 + 32; + spawned->s->lotag = a2->s->lotag; + if (spawned->s->lotag == 3 || spawned->s->lotag == 5) + { + spawned->s->clipdist = (1 + (krand() % 1)) * 16 + 32; + } + else + { + spawned->s->clipdist = (1 + (krand() % 1)) * 16 + 32; + } + spawned->s->ang -= ((krand() & 32) - (krand() & 64)) & 2047; } - else - { - spawned->s->clipdist = (1 + (krand() % 1)) * 16 + 32; - } - spawned->s->ang -= ((krand() & 32) - (krand() & 64)) & 2047; } if (a2->s->picnum == 280) tag = a2->s->hitag; diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index 928108207..202788829 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -94,14 +94,17 @@ static int ccmd_spawn(CCmdFuncPtr parm) } auto spawned = spawn(ps[myconnectindex].GetActor(), picnum); - if (set & 1) spawned->s->pal = (uint8_t)pal; - if (set & 2) spawned->s->cstat = (uint16_t)cstat; - if (set & 4) spawned->s->ang = ang; - if (set & 8) { - if (setsprite(spawned, x, y, z) < 0) - { - Printf("spawn: Sprite can't be spawned into null space\n"); - deletesprite(spawned); + if (spawned) + { + if (set & 1) spawned->s->pal = (uint8_t)pal; + if (set & 2) spawned->s->cstat = (uint16_t)cstat; + if (set & 4) spawned->s->ang = ang; + if (set & 8) { + if (setsprite(spawned, x, y, z) < 0) + { + Printf("spawn: Sprite can't be spawned into null space\n"); + deletesprite(spawned); + } } } diff --git a/source/games/duke/src/cheats.cpp b/source/games/duke/src/cheats.cpp index 36cae4a61..6aa53b794 100644 --- a/source/games/duke/src/cheats.cpp +++ b/source/games/duke/src/cheats.cpp @@ -121,9 +121,12 @@ static const char *cheatKfc(int player) for (int i = 0; i < 7; i++) { auto spr = spawn(ps[player].GetActor(), TILE_HEN); - spr->s->pal = 1; - spr->s->xrepeat = spr->s->xrepeat << 2; - spr->s->yrepeat = spr->s->yrepeat << 2; + if (spr) + { + spr->s->pal = 1; + spr->s->xrepeat = spr->s->xrepeat << 2; + spr->s->yrepeat = spr->s->yrepeat << 2; + } } return quoteMgr.GetQuote(QUOTE_CHEAT_KFC); } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 74c8b20ca..5dc94bc20 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -515,8 +515,11 @@ void footprints(int snum) case 2: fprint = spawn(actor, TILE_FOOTPRINTS3); break; default: fprint = spawn(actor, TILE_FOOTPRINTS4); break; } - fprint->s->pal = p->footprintpal; - fprint->s->shade = (int8_t)p->footprintshade; + if (fprint) + { + fprint->s->pal = p->footprintpal; + fprint->s->shade = (int8_t)p->footprintshade; + } } } } @@ -1036,17 +1039,20 @@ void shootbloodsplat(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, i if (wal->hitag == 0) { auto spawned = spawn(actor, atwith); - spawned->s->xvel = -12; - auto delta = wal->delta(); - spawned->s->ang = getangle(-delta.x, -delta.y) + 512; // note the '-' sign here! - spawned->s->x = hitx; - spawned->s->y = hity; - spawned->s->z = hitz; - spawned->s->cstat |= (krand() & 4); - ssp(spawned, CLIPMASK0); - setsprite(spawned, spawned->s->pos); - if (s->picnum == OOZFILTER || s->picnum == NEWBEAST) - spawned->s->pal = 6; + if (spawned) + { + spawned->s->xvel = -12; + auto delta = wal->delta(); + spawned->s->ang = getangle(-delta.x, -delta.y) + 512; // note the '-' sign here! + spawned->s->x = hitx; + spawned->s->y = hity; + spawned->s->z = hitz; + spawned->s->cstat |= (krand() & 4); + ssp(spawned, CLIPMASK0); + setsprite(spawned, spawned->s->pos); + if (s->picnum == OOZFILTER || s->picnum == NEWBEAST) + spawned->s->pal = 6; + } } } } diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index c5cf98875..3a696455d 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -196,6 +196,7 @@ static void shootflamethrowerflame(DDukeActor* actor, int p, int sx, int sy, int if (spawned == nullptr) { spawned = spawn(actor, FLAMETHROWERFLAME); + if (!spawned) return; spawned->s->xvel = (short)vel; spawned->s->zvel = (short)zvel; } @@ -273,7 +274,7 @@ static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) if (p >= 0) { auto k = spawn(knee, SMALLSMOKE); - k->s->z -= (8 << 8); + if (k) k->s->z -= (8 << 8); S_PlayActorSound(KICK_HIT, knee); } @@ -304,12 +305,15 @@ static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) else if (p >= 0 && zvel > 0 && hitsectp->lotag == 1) { auto splash = spawn(ps[p].GetActor(), WATERSPLASH2); - splash->s->x = hitx; - splash->s->y = hity; - splash->s->ang = ps[p].angle.ang.asbuild(); // Total tweek - splash->s->xvel = 32; - ssp(actor, CLIPMASK0); - splash->s->xvel = 0; + if (splash) + { + splash->s->x = hitx; + splash->s->y = hity; + splash->s->ang = ps[p].angle.ang.asbuild(); // Total tweek + splash->s->xvel = 32; + ssp(actor, CLIPMASK0); + splash->s->xvel = 0; + } } } @@ -453,12 +457,15 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa fi.checkhitsprite(hitact, spark); if (hitact->s->picnum == TILE_APLAYER && (ud.coop != 1 || ud.ffire == 1)) { - auto jib = spawn(spark, JIBS6); spark->s->xrepeat = spark->s->yrepeat = 0; - jib->s->z += (4 << 8); - jib->s->xvel = 16; - jib->s->xrepeat = jib->s->yrepeat = 24; - jib->s->ang += 64 - (krand() & 127); + auto jib = spawn(spark, JIBS6); + if (jib) + { + jib->s->z += (4 << 8); + jib->s->xvel = 16; + jib->s->xrepeat = jib->s->yrepeat = 24; + jib->s->ang += 64 - (krand() & 127); + } } else spawn(spark, SMALLSMOKE); @@ -524,10 +531,13 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa goto SKIPBULLETHOLE; } auto hole = spawn(spark, BULLETHOLE); - hole->s->xvel = -1; - auto delta = wal->delta(); - hole->s->ang = getangle(-delta.x, -delta.y) + 512; - ssp(hole, CLIPMASK0); + if (hole) + { + hole->s->xvel = -1; + auto delta = wal->delta(); + hole->s->ang = getangle(-delta.x, -delta.y) + 512; + ssp(hole, CLIPMASK0); + } } SKIPBULLETHOLE: @@ -1089,13 +1099,16 @@ void shoot_d(DDukeActor* actor, int atwith) case FIREFLY: // BOSS5 shot { auto k = spawn(actor, atwith); - k->s->sectnum = sectnum(sect); - k->s->x = sx; - k->s->y = sy; - k->s->z = sz; - k->s->ang = sa; - k->s->xvel = 500; - k->s->zvel = 0; + if (k) + { + k->s->sectnum = sectnum(sect); + k->s->x = sx; + k->s->y = sy; + k->s->z = sz; + k->s->ang = sa; + k->s->xvel = 500; + k->s->zvel = 0; + } return; } } @@ -2015,11 +2028,14 @@ static void underwater(int snum, ESyncBits actions, int fz, int cz) if (p->scuba_on && (krand() & 255) < 8) { auto j = spawn(pact, WATERBUBBLE); - j->s->x += bcos(p->angle.ang.asbuild() + 64 - (global_random & 128), -6); - j->s->y += bsin(p->angle.ang.asbuild() + 64 - (global_random & 128), -6); - j->s->xrepeat = 3; - j->s->yrepeat = 2; - j->s->z = p->pos.z + (8 << 8); + if (j) + { + j->s->x += bcos(p->angle.ang.asbuild() + 64 - (global_random & 128), -6); + j->s->y += bsin(p->angle.ang.asbuild() + 64 - (global_random & 128), -6); + j->s->xrepeat = 3; + j->s->yrepeat = 2; + j->s->z = p->pos.z + (8 << 8); + } } } @@ -2377,9 +2393,12 @@ static void operateweapon(int snum, ESyncBits actions, int psect) case 24: { auto j = spawn(pact, SHOTGUNSHELL); - j->s->ang += 1024; - ssp(j, CLIPMASK0); - j->s->ang += 1024; + if (j) + { + j->s->ang += 1024; + ssp(j, CLIPMASK0); + j->s->ang += 1024; + } p->kickback_pic++; break; } @@ -2402,12 +2421,14 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if ((p->kickback_pic % 3) == 0) { auto j = spawn(pact, SHELL); - - j->s->ang += 1024; - j->s->ang &= 2047; - j->s->xvel += 32; - j->s->z += (3 << 8); - ssp(j, CLIPMASK0); + if (j) + { + j->s->ang += 1024; + j->s->ang &= 2047; + j->s->xvel += 32; + j->s->z += (3 << 8); + ssp(j, CLIPMASK0); + } } S_PlayActorSound(CHAINGUN_FIRE, pact); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index c08675082..f3f62835f 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -161,7 +161,7 @@ static void shootmelee(DDukeActor *actor, int p, int sx, int sy, int sz, int sa, if (p >= 0) { auto k = spawn(wpn, SMALLSMOKE); - k->s->z -= (8 << 8); + if (k) k->s->z -= (8 << 8); if (atwith == KNEE) S_PlayActorSound(KICK_HIT, wpn); else if (isRRRA() && atwith == SLINGBLADE) S_PlayActorSound(260, wpn); } @@ -191,12 +191,15 @@ static void shootmelee(DDukeActor *actor, int p, int sx, int sy, int sz, int sa, else if (p >= 0 && zvel > 0 && hitsectp->lotag == 1) { auto splash = spawn(ps[p].GetActor(), WATERSPLASH2); - splash->s->x = hitx; - splash->s->y = hity; - splash->s->ang = ps[p].angle.ang.asbuild(); // Total tweek - splash->s->xvel = 32; - ssp(actor, 0); - splash->s->xvel = 0; + if (splash) + { + splash->s->x = hitx; + splash->s->y = hity; + splash->s->ang = ps[p].angle.ang.asbuild(); // Total tweek + splash->s->xvel = 32; + ssp(actor, 0); + splash->s->xvel = 0; + } } } } @@ -344,10 +347,13 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa { auto l = spawn(spark, JIBS6); spark->s->xrepeat = spark->s->yrepeat = 0; - l->s->z += (4 << 8); - l->s->xvel = 16; - l->s->xrepeat = l->s->yrepeat = 24; - l->s->ang += 64 - (krand() & 127); + if (l) + { + l->s->z += (4 << 8); + l->s->xvel = 16; + l->s->xrepeat = l->s->yrepeat = 24; + l->s->ang += 64 - (krand() & 127); + } } else spawn(spark, SMALLSMOKE); @@ -416,10 +422,13 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa goto SKIPBULLETHOLE; } auto l = spawn(spark, BULLETHOLE); - l->s->xvel = -1; - auto delta = wal->delta(); - l->s->ang = getangle(-delta.x, -delta.y) + 512; - ssp(l, CLIPMASK0); + if (l) + { + l->s->xvel = -1; + auto delta = wal->delta(); + l->s->ang = getangle(-delta.x, -delta.y) + 512; + ssp(l, CLIPMASK0); + } } SKIPBULLETHOLE: @@ -903,17 +912,23 @@ void shoot_r(DDukeActor* actor, int atwith) case TRIPBOMBSPRITE: { auto j = spawn(actor, atwith); - j->s->xvel = 32; - j->s->ang = s->ang; - j->s->z -= (5 << 8); + if (j) + { + j->s->xvel = 32; + j->s->ang = s->ang; + j->s->z -= (5 << 8); + } break; } case BOWLINGBALL: { auto j = spawn(actor, atwith); - j->s->xvel = 250; - j->s->ang = s->ang; - j->s->z -= (15 << 8); + if (j) + { + j->s->xvel = 250; + j->s->ang = s->ang; + j->s->z -= (15 << 8); + } break; } case OWHIP: @@ -1505,8 +1520,11 @@ void checkweapons_r(struct player_struct* p) if (p->OnMotorcycle && numplayers > 1) { auto j = spawn(p->GetActor(), 7220); - j->s->ang = p->angle.ang.asbuild(); - j->saved_ammo = p->ammo_amount[MOTORCYCLE_WEAPON]; + if (j) + { + j->s->ang = p->angle.ang.asbuild(); + j->saved_ammo = p->ammo_amount[MOTORCYCLE_WEAPON]; + } p->OnMotorcycle = 0; p->gotweapon[MOTORCYCLE_WEAPON] = false; p->horizon.horiz = q16horiz(0); @@ -1521,8 +1539,11 @@ void checkweapons_r(struct player_struct* p) else if (p->OnBoat && numplayers > 1) { auto j = spawn(p->GetActor(), 7233); - j->s->ang = p->angle.ang.asbuild(); - j->saved_ammo = p->ammo_amount[BOAT_WEAPON]; + if (j) + { + j->s->ang = p->angle.ang.asbuild(); + j->saved_ammo = p->ammo_amount[BOAT_WEAPON]; + } p->OnBoat = 0; p->gotweapon[BOAT_WEAPON] = false; p->horizon.horiz = q16horiz(0); @@ -1557,7 +1578,7 @@ void checkweapons_r(struct player_struct* p) if (p->keys[i] == 1) { auto j = spawn(p->GetActor(), ACCESSCARD); - switch (i) + if (j) switch (i) { case 1: j->s->lotag = 100; @@ -2344,12 +2365,15 @@ static void underwater(int snum, ESyncBits actions, int fz, int cz) if (p->scuba_on && (krand() & 255) < 8) { auto j = spawn(pact, WATERBUBBLE); - j->s->x += bcos(p->angle.ang.asbuild() + 64 - (global_random & 128) + 128, -6); - j->s->y += bsin(p->angle.ang.asbuild() + 64 - (global_random & 128) + 128, -6); - j->s->xrepeat = 3; - j->s->yrepeat = 2; - j->s->z = p->pos.z + (8 << 8); - j->s->cstat = 514; + if (j) + { + j->s->x += bcos(p->angle.ang.asbuild() + 64 - (global_random & 128) + 128, -6); + j->s->y += bsin(p->angle.ang.asbuild() + 64 - (global_random & 128) + 128, -6); + j->s->xrepeat = 3; + j->s->yrepeat = 2; + j->s->z = p->pos.z + (8 << 8); + j->s->cstat = 514; + } } } @@ -2973,12 +2997,15 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) if ((p->kickback_pic % 3) == 0) { auto j = spawn(pact, SHELL); + if (j) + { - j->s->ang += 1024; - j->s->ang &= 2047; - j->s->xvel += 32; - j->s->z += (3 << 8); - ssp(j, CLIPMASK0); + j->s->ang += 1024; + j->s->ang &= 2047; + j->s->xvel += 32; + j->s->z += (3 << 8); + ssp(j, CLIPMASK0); + } } S_PlayActorSound(CHAINGUN_FIRE, pact); @@ -4090,10 +4117,13 @@ void OffMotorcycle(struct player_struct *p) p->posyv -= p->angle.ang.bsin(7); p->moto_underwater = 0; auto spawned = spawn(p->GetActor(), EMPTYBIKE); - spawned->s->ang = p->angle.ang.asbuild(); - spawned->s->xvel += p->angle.ang.bcos(7); - spawned->s->yvel += p->angle.ang.bsin(7); - spawned->saved_ammo = p->ammo_amount[MOTORCYCLE_WEAPON]; + if (spawned) + { + spawned->s->ang = p->angle.ang.asbuild(); + spawned->s->xvel += p->angle.ang.bcos(7); + spawned->s->yvel += p->angle.ang.bsin(7); + spawned->saved_ammo = p->ammo_amount[MOTORCYCLE_WEAPON]; + } } } @@ -4154,10 +4184,13 @@ void OffBoat(struct player_struct *p) p->posyv -= p->angle.ang.bsin(7); p->moto_underwater = 0; auto spawned = spawn(p->GetActor(), EMPTYBOAT); - spawned->s->ang = p->angle.ang.asbuild(); - spawned->s->xvel += p->angle.ang.bcos(7); - spawned->s->yvel += p->angle.ang.bsin(7); - spawned->saved_ammo = p->ammo_amount[BOAT_WEAPON]; + if (spawned) + { + spawned->s->ang = p->angle.ang.asbuild(); + spawned->s->xvel += p->angle.ang.bcos(7); + spawned->s->yvel += p->angle.ang.bsin(7); + spawned->saved_ammo = p->ammo_amount[BOAT_WEAPON]; + } } } diff --git a/source/games/duke/src/player_w.cpp b/source/games/duke/src/player_w.cpp index 935df4d24..bf6c80867 100644 --- a/source/games/duke/src/player_w.cpp +++ b/source/games/duke/src/player_w.cpp @@ -112,6 +112,7 @@ void DoSpawn(struct player_struct *p, int snum) return; auto j = spawn(p->GetActor(), aplWeaponSpawn[p->curr_weapon][snum]); + if (!j) return; if((aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_SPAWNTYPE2 ) ) { diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 53cdf3994..c83891a4f 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -197,9 +197,12 @@ void operaterespawns_d(int low) if (badguypic(act->s->hitag) && ud.monsters_off) break; auto star = spawn(act, TRANSPORTERSTAR); - star->s->z -= (32 << 8); + if (star) + { + star->s->z -= (32 << 8); - act->s->extra = 66 - 12; // Just a way to killit + act->s->extra = 66 - 12; // Just a way to killit + } break; } } @@ -1311,7 +1314,7 @@ void checkhitsprite_d(DDukeActor* targ, DDukeActor* proj) } { auto j = spawn(targ, STEAM); - j->s->z = s->sector()->floorz - (32 << 8); + if (j) j->s->z = s->sector()->floorz - (32 << 8); } break; @@ -1394,12 +1397,15 @@ void checkhitsprite_d(DDukeActor* targ, DDukeActor* proj) //if (actortype[s->picnum] == 0) //TRANSITIONAL. Cannot be done right with EDuke mess backing the engine. { auto spawned = spawn(proj, JIBS6); - if (pspr->pal == 6) - spawned->s->pal = 6; - spawned->s->z += (4 << 8); - spawned->s->xvel = 16; - spawned->s->xrepeat = spawned->s->yrepeat = 24; - spawned->s->ang += 32 - (krand() & 63); + if (spawned) + { + if (pspr->pal == 6) + spawned->s->pal = 6; + spawned->s->z += (4 << 8); + spawned->s->xvel = 16; + spawned->s->xrepeat = spawned->s->yrepeat = 24; + spawned->s->ang += 32 - (krand() & 63); + } } auto Owner = proj->GetOwner(); diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 7766dde20..b598e16e7 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -313,7 +313,7 @@ void operaterespawns_r(int low) if (badguypic(act->s->hitag) && ud.monsters_off) break; auto star = spawn(act, TRANSPORTERSTAR); - star->s->z -= (32 << 8); + if (star) star->s->z -= (32 << 8); act->s->extra = 66 - 12; // Just a way to killit break; @@ -2328,7 +2328,7 @@ void checkhitsprite_r(DDukeActor* targ, DDukeActor* proj) } { auto j = spawn(targ, STEAM); - j->s->z = s->sector()->floorz - (32 << 8); + if (j) j->s->z = s->sector()->floorz - (32 << 8); } break; @@ -2371,12 +2371,15 @@ void checkhitsprite_r(DDukeActor* targ, DDukeActor* proj) //if (actortype[s->picnum] == 0) //TRANSITIONAL. Cannot be done right with EDuke mess backing the engine. { auto spawned = spawn(proj, JIBS6); - if (pspr->pal == 6) - spawned->s->pal = 6; - spawned->s->z += (4 << 8); - spawned->s->xvel = 16; - spawned->s->xrepeat = spawned->s->yrepeat = 24; - spawned->s->ang += 32 - (krand() & 63); + if (spawned) + { + if (pspr->pal == 6) + spawned->s->pal = 6; + spawned->s->z += (4 << 8); + spawned->s->xvel = 16; + spawned->s->xrepeat = spawned->s->yrepeat = 24; + spawned->s->ang += 32 - (krand() & 63); + } } auto Owner = proj->GetOwner();