From 4ad1349113d2b70fce3d24df14c11b6a73e5eca3 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 --- d3xp/Weapon.cpp | 9 ++++++++- game/Weapon.cpp | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/d3xp/Weapon.cpp b/d3xp/Weapon.cpp index 2101381..30f8882 100644 --- a/d3xp/Weapon.cpp +++ b/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/game/Weapon.cpp b/game/Weapon.cpp index d889c68..a381ae2 100644 --- a/game/Weapon.cpp +++ b/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();