Skip to content
Permalink
Browse files

Fix crash when attempting to stream out a sound that's not streamed in

  • Loading branch information...
sbx320 committed Sep 3, 2019
1 parent 25ffe62 commit e1b7c730448d12a5eeb452239e8053e86924294f
Showing with 3 additions and 5 deletions.
  1. +3 −5 Client/mods/deathmatch/logic/CClientSoundManager.cpp
@@ -350,17 +350,15 @@ void CClientSoundManager::UpdateDistanceStreaming(const CVector& vecListenerPosi
// If the sound is more than 40 units away (or in another dimension), make sure it is deactivated
// If the sound is less than 20 units away, make sure it is activated
//
for (std::set<CClientSound*>::iterator iter = considerMap.begin(); iter != considerMap.end(); ++iter)
for (CClientSound* pSound : considerMap)
{
CClientSound* pSound = *iter;

// Calculate distance to the edge of the sphere
CSphere sphere = pSound->GetWorldBoundingSphere();
float fDistance = (vecListenerPosition - sphere.vecPosition).Length() - sphere.fRadius;

if (fDistance > 40 || m_usDimension != pSound->GetDimension())
if ((fDistance > 40 || m_usDimension != pSound->GetDimension() && MapContains(m_DistanceStreamedInMap, pSound)))
pSound->DistanceStreamOut();
else if (fDistance < 20)
else if (fDistance < 20)
pSound->DistanceStreamIn();
}
}

2 comments on commit e1b7c73

@sbx320

This comment has been minimized.

Copy link
Member Author

replied Sep 3, 2019

Issue here is related to GetClientSpatialDatabase()->SphereQuery(result, CSphere(vecListenerPosition, 0)); not actually using a sphere to figure out which sounds are on the same position as the camera. In CClientSpatialDatabaseImpl::SphereQuery we have a comment indicating it only uses 2D:

   // Make a box from the sphere
   CBox box(sphere.vecPosition, fabsf(sphere.fRadius));
   // Make everything 2D for now
   box.vecMin.fZ = SPATIAL_2D_Z;
   box.vecMax.fZ = SPATIAL_2D_Z;

Thus the sphere query may also return sounds that are on the same X/Y position, but are a significant distance away on the Z axis. As we then use the 3D distance (e1b7c73#diff-006374c94febb6b1e96e14d6e51cf875R357) to figure out whether to stream the sound in or out, we may attempt to stream out a sound that is not streamed in yet. This then leads to a crash due to an assertion in CClientSoundManager::OnDistanceStreamOut.

@Dutchman101

This comment has been minimized.

Copy link
Contributor

replied Sep 3, 2019

For the record; while it was always unsafe (due to what sbx320 said), it's likely that PR #834 introduced a significant chance to get this crash (even without turning off external sounds).

Apparently, as @patrikjuvonen also thought could be the case, more was needed than just handling stream-in with this change (part of said PR): 28a9a2b

The crash should be fixed now, but maybe it's a good idea to ensure this change suffices in the light of relevant changes made by the PR (if it's a complete, proper solution)

Please sign in to comment.
You can’t perform that action at this time.