Bladeren bron

Fixed crash when switching test scenes in CharacterBaseTest

Jorrit Rouwe 10 maanden geleden
bovenliggende
commit
5f74424272
1 gewijzigde bestanden met toevoegingen van 28 en 27 verwijderingen
  1. 28 27
      Samples/Tests/Character/CharacterBaseTest.cpp

+ 28 - 27
Samples/Tests/Character/CharacterBaseTest.cpp

@@ -637,33 +637,34 @@ void CharacterBaseTest::PrePhysicsUpdate(const PreUpdateParams &inParams)
 
 	// Animate character virtual
 	for (CharacterVirtual *character : { mAnimatedCharacterVirtual, mAnimatedCharacterVirtualWithInnerBody })
-	{
-	#ifdef JPH_DEBUG_RENDERER
-		character->GetShape()->Draw(mDebugRenderer, character->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), Color::sOrange, false, true);
-	#else
-		mDebugRenderer->DrawCapsule(character->GetCenterOfMassTransform(), 0.5f * cCharacterHeightStanding, cCharacterRadiusStanding + character->GetCharacterPadding(), Color::sOrange, DebugRenderer::ECastShadow::Off, DebugRenderer::EDrawMode::Wireframe);
-	#endif // JPH_DEBUG_RENDERER
-
-		// Update velocity and apply gravity
-		Vec3 velocity;
-		if (character->GetGroundState() == CharacterVirtual::EGroundState::OnGround)
-			velocity = Vec3::sZero();
-		else
-			velocity = character->GetLinearVelocity() * mAnimatedCharacter->GetUp() + mPhysicsSystem->GetGravity() * inParams.mDeltaTime;
-		velocity += Sin(mTime) * cCharacterVelocity;
-		character->SetLinearVelocity(velocity);
-
-		// Move character
-		CharacterVirtual::ExtendedUpdateSettings update_settings;
-		character->ExtendedUpdate(inParams.mDeltaTime,
-			mPhysicsSystem->GetGravity(),
-			update_settings,
-			mPhysicsSystem->GetDefaultBroadPhaseLayerFilter(Layers::MOVING),
-			mPhysicsSystem->GetDefaultLayerFilter(Layers::MOVING),
-			{ },
-			{ },
-			*mTempAllocator);
-	}
+		if (character != nullptr)
+		{
+		#ifdef JPH_DEBUG_RENDERER
+			character->GetShape()->Draw(mDebugRenderer, character->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), Color::sOrange, false, true);
+		#else
+			mDebugRenderer->DrawCapsule(character->GetCenterOfMassTransform(), 0.5f * cCharacterHeightStanding, cCharacterRadiusStanding + character->GetCharacterPadding(), Color::sOrange, DebugRenderer::ECastShadow::Off, DebugRenderer::EDrawMode::Wireframe);
+		#endif // JPH_DEBUG_RENDERER
+
+			// Update velocity and apply gravity
+			Vec3 velocity;
+			if (character->GetGroundState() == CharacterVirtual::EGroundState::OnGround)
+				velocity = Vec3::sZero();
+			else
+				velocity = character->GetLinearVelocity() * mAnimatedCharacter->GetUp() + mPhysicsSystem->GetGravity() * inParams.mDeltaTime;
+			velocity += Sin(mTime) * cCharacterVelocity;
+			character->SetLinearVelocity(velocity);
+
+			// Move character
+			CharacterVirtual::ExtendedUpdateSettings update_settings;
+			character->ExtendedUpdate(inParams.mDeltaTime,
+				mPhysicsSystem->GetGravity(),
+				update_settings,
+				mPhysicsSystem->GetDefaultBroadPhaseLayerFilter(Layers::MOVING),
+				mPhysicsSystem->GetDefaultLayerFilter(Layers::MOVING),
+				{ },
+				{ },
+				*mTempAllocator);
+		}
 
 	// Reset ramp blocks
 	mRampBlocksTimeLeft -= inParams.mDeltaTime;