AndresTraks / BulletSharp

.NET wrapper for the Bullet physics library
http://andrestraks.github.io/BulletSharp
MIT License
273 stars 59 forks source link

AccessViolationException while BulletSharp.DynamicsWorld.StepSimulation #54

Closed Sphaerichthys closed 6 years ago

Sphaerichthys commented 6 years ago

I have a random reproduce of the issue. What I do: 1.Create DynamicWorld:

            var collisionConf = new DefaultCollisionConfiguration();
            var dispatcher = new CollisionDispatcher(collisionConf);
            var broadphase = new AxisSweep3(new Vector3(-200, -200, -200), new Vector3(200, 200, 200));
            var solver = new SequentialImpulseConstraintSolver();

            var world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConf);

            broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback());

2.Create some plane or some map and add it to the world. 3.Add KinematicCharacterMovementController to the world:

                    var identity = Matrix.Identity;

                    var ghostObject = new PairCachingGhostObject
                    {
                        CollisionShape = capsule,
                        CollisionFlags = CollisionFlags.CharacterObject,
                        WorldTransform = identity,
                        ActivationState = ActivationState.DisableDeactivation
                    };
                    worldManager.AddCollisionObject(ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter);

                    var character = new KinematicCharacterController(ghostObject, capsule, GameServerSettings.CharacterStepHight);
                    worldManager.AddAction(character);
                    return new KinematicCharacterMovementController(character);

When I add several character controllers to the world I get

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at BulletSharp.DynamicsWorld.StepSimulation(Single timeStep)

randomly from time to time with no further details.

AndresTraks commented 6 years ago

I did find an issue in KinematicCharacterController where a wrong block of memory was being freed. It is fixed here: https://github.com/AndresTraks/BulletSharp/commit/6124d85c4b9c89248a295f4a744a541f7338ce1a

Sphaerichthys commented 6 years ago

That helped, thank you.