AndresTraks / BulletSharp

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

TypeInitialisationException was unhandled at new BulletSharp.RaycastVehicle(); #31

Open mifwarior opened 8 years ago

mifwarior commented 8 years ago

Having TypeInitialisationException was unhandled at new BulletSharp.RaycastVehicle();

public void SetupVechine(DynamicsWorld world, CollisionShape shape, Matrix vehicleTr, DefaultVehicleRaycaster raycaster) { RigidBody carChassis = LocalCreateRigidBody(800, vehicleTr, shape);

        carChassis.UserObject = "Chassis";
        carChassis.SetDamping(0.2f, 0.2f);

        world.AddRigidBody(carChassis);

        RaycastVehicle.VehicleTuning tuning = new RaycastVehicle.VehicleTuning();
        vehicle = new BulletSharp.RaycastVehicle(tuning, carChassis, raycaster);

}

reproduce at newest version, with old version it's all okey

AndresTraks commented 8 years ago

This can happen if you update the BulletSharp reference in one project, but not another. The runtime expects the newer type, but sees the old type or vice versa. Try rebuilding the entire solution and check that only the newest BulletSharp is referenced everywhere.

You can also check if the VehicleDemo (in demos/Generic) works. I couldn't reproduce the exception.

mifwarior commented 8 years ago

Ok, in visual studio it works ok, but when i run builded file alone - have exception Perhaps it's my fault, I was wrong to build "BulletSharp.dll". I build it for "generic". I traced the error. It is called from RigidBody_GetUnmanagedConstructionInfo in RigidBodyConstructionInfo::RigidBodyConstructionInfo(btScalar mass, BulletSharp::MotionState^ motionState, BulletSharp::CollisionShape^ collisionShape)

mifwarior commented 8 years ago

I make a test. Build BulletSharp.dll release and debug mode. Debug mode - work clearly, Release - don't work with exception

mifwarior commented 8 years ago

I found a solution: Since running a separate (without studio) application displays more information about the error, I got an error AccessViolation.

Google helped: https://code.google.com/p/bulletsharp/issues/detail?id=52 http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=8180

i change BulletSharp in RaycastVehicle.cpp (line 85), at static RaycastVehicle::RaycastVehicle() original: RigidBodyConstructionInfo^ info = gcnew RigidBodyConstructionInfo(0, nullptr, nullptr); by: RigidBodyConstructionInfo^ info = gcnew RigidBodyConstructionInfo(0, nullptr, nullptr,Vector3_Zero); and all works!

AndresTraks commented 8 years ago

I added tests for the RigidBodyConstructionInfo constructor, but couldn't get the access violation. I do remember this issue popping up every now and then.

Can you tell me what your CPU model is? I'm wondering if it could be because of missing SSE support.

mifwarior commented 8 years ago

https://gist.github.com/mifwarior/6591954f8a48b128e2cf

I'm certainly not the master of C ++, but I have a suspicion that it was not related to the SSE, but it is my guess. I have 2 computers, one is new, the other one is old and was obtained on both the error. The problem occurs every start.