From b03fc9271aa5c4aaf4e90a940c78d004e2962148 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 13 Dec 2015 03:06:52 +0100 Subject: [PATCH] Fix crash by assert in last RoE level (and maybe elsewhere) The assertion in idBounds::operator-(const idBounds&) was triggered from idWeapon::Event_LaunchProjectiles() (ownerBounds - projBounds) It only happened when using the BFG. So I added a check to make sure calling operator- is legal. I guess this also caused #122 --- neo/d3xp/Weapon.cpp | 9 ++++++++- neo/game/Weapon.cpp | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/neo/d3xp/Weapon.cpp b/neo/d3xp/Weapon.cpp index 21013818..30f8882b 100644 --- a/neo/d3xp/Weapon.cpp +++ b/neo/d3xp/Weapon.cpp @@ -3446,7 +3446,14 @@ void idWeapon::Event_LaunchProjectiles( int num_projectiles, float spread, float // make sure the projectile starts inside the bounding box of the owner if ( i == 0 ) { muzzle_pos = muzzleOrigin + playerViewAxis[ 0 ] * 2.0f; - if ( ( ownerBounds - projBounds).RayIntersection( muzzle_pos, playerViewAxis[0], distance ) ) { + + // DG: sometimes the assertion in idBounds::operator-(const idBounds&) triggers + // (would get bounding box with negative volume) + // => check that before doing ownerBounds - projBounds (equivalent to the check in the assertion) + idVec3 obDiff = ownerBounds[1] - ownerBounds[0]; + idVec3 pbDiff = projBounds[1] - projBounds[0]; + bool boundsSubLegal = obDiff.x > pbDiff.x && obDiff.y > pbDiff.y && obDiff.z > pbDiff.z; + if ( boundsSubLegal && ( ownerBounds - projBounds ).RayIntersection( muzzle_pos, playerViewAxis[0], distance ) ) { start = muzzle_pos + distance * playerViewAxis[0]; } else { start = ownerBounds.GetCenter(); diff --git a/neo/game/Weapon.cpp b/neo/game/Weapon.cpp index d889c685..a381ae24 100644 --- a/neo/game/Weapon.cpp +++ b/neo/game/Weapon.cpp @@ -2941,7 +2941,13 @@ void idWeapon::Event_LaunchProjectiles( int num_projectiles, float spread, float // make sure the projectile starts inside the bounding box of the owner if ( i == 0 ) { muzzle_pos = muzzleOrigin + playerViewAxis[ 0 ] * 2.0f; - if ( ( ownerBounds - projBounds).RayIntersection( muzzle_pos, playerViewAxis[0], distance ) ) { + // DG: sometimes the assertion in idBounds::operator-(const idBounds&) triggers + // (would get bounding box with negative volume) + // => check that before doing ownerBounds - projBounds (equivalent to the check in the assertion) + idVec3 obDiff = ownerBounds[1] - ownerBounds[0]; + idVec3 pbDiff = projBounds[1] - projBounds[0]; + bool boundsSubLegal = obDiff.x > pbDiff.x && obDiff.y > pbDiff.y && obDiff.z > pbDiff.z; + if ( boundsSubLegal && ( ownerBounds - projBounds ).RayIntersection( muzzle_pos, playerViewAxis[0], distance ) ) { start = muzzle_pos + distance * playerViewAxis[0]; } else { start = ownerBounds.GetCenter();