Skip to content

[MISC] prop_dynamic with modified model scale and no physics object crashes the game #202

@Blixibon

Description

@Blixibon

Describe the bug

Having a prop_dynamic with a modified model scale and no physics object will crash the game. This seems to be unique to Mapbase v7.0.

Steps to reproduce

Steps to reproduce the behavior:

  1. Add a prop_dynamic into a map with a non-1 model scale and no physics object
  2. Game should crash

Expected behavior

The game should not crash under these circumstances. It did not crash prior to Mapbase v7.0.


Additional context

This appears to be caused by some new code added to CDynamicProp::TestCollision in Mapbase v7.0:

bool CDynamicProp::TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace )
{
	if ( IsSolidFlagSet(FSOLID_NOT_SOLID) )
	{
		// if this entity is marked non-solid and custom test it must have bone followers
		if ( IsSolidFlagSet( FSOLID_CUSTOMBOXTEST ) && IsSolidFlagSet( FSOLID_CUSTOMRAYTEST ))
		{
			for ( int i = 0; i < m_BoneFollowerManager.GetNumBoneFollowers(); i++ )
			{
				CBaseEntity *pEntity = m_BoneFollowerManager.GetBoneFollower(i)->hFollower;
				if ( pEntity && pEntity->TestCollision(ray, mask, trace) )
					return true;
			}
		}
	}
+#ifdef MAPBASE // From Alien Swarm SDK
+	return BaseClass::TestCollision( ray, mask, trace );
+#else
	return false;
+#endif
}

The base function, CBaseAnimating::TestCollision, is not designed to allow a prop with a unique model scale and no physics object.

bool CBaseAnimating::TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr )
{
	// Return a special case for scaled physics objects
	if ( GetModelScale() != 1.0f )
	{
		IPhysicsObject *pPhysObject = VPhysicsGetObject();
		Vector vecPosition;
		QAngle vecAngles;
		pPhysObject->GetPosition( &vecPosition, &vecAngles );
		const CPhysCollide *pScaledCollide = pPhysObject->GetCollide();
		physcollision->TraceBox( ray, pScaledCollide, vecPosition, vecAngles, &tr );
		
		return tr.DidHit();
	}

However, the Alien Swarm SDK has its own version of this code which fixes the problem by just checking for pPhysObject first:

bool CBaseAnimating::TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr )
{
	IPhysicsObject *pPhysObject = VPhysicsGetObject();
	// Return a special case for scaled physics objects
	// FIXME: need to have scaled hitbox for scaled models for this to work, we can't assume everything has a VPhysics object
	if ( GetModelScale() != 1.0f && pPhysObject )
	{
		Vector vecPosition;
		QAngle vecAngles;
		pPhysObject->GetPosition( &vecPosition, &vecAngles );
		const CPhysCollide *pScaledCollide = pPhysObject->GetCollide();
		physcollision->TraceBox( ray, pScaledCollide, vecPosition, vecAngles, &tr );
		
		return tr.DidHit();
	}

Fixing this issue would entail either removing the new code from CDynamicProp::TestCollision or adding the additional code to CBaseAnimating::TestCollision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingCrashMapbase - Crashes the game (higher priority than a bug)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions