使用以下启动:
BulletSharp.DefaultCollisionConstructionInfo collisionConstructionInfo =
new BulletSharp.DefaultCollisionConstructionInfo();
BulletSharp.DefaultCollisionConfiguration collisionConfiguration =
new BulletSharp.DefaultCollisionConfiguration(
collisionConstructionInfo );
BulletSharp.Dispatcher collisionDispatcher =
new BulletSharp.CollisionDispatcher(
collisionConfiguration );
BulletSharp.BroadphaseInterface broadPhaseCollisionInterface =
new BulletSharp.SimpleBroadphase( );
BulletSharp.CollisionWorld bulletCollisionWorld =
new BulletSharp.CollisionWorld(
collisionDispatcher,
broadPhaseCollisionInterface,
collisionConfiguration );
BulletSharp.ConstraintSolver constraintSolver =
new BulletSharp.SequentialImpulseConstraintSolver();
BulletSharp.DynamicsWorld bulletDynamicsWorld =
new BulletSharp.DiscreteDynamicsWorld(
collisionDispatcher,
broadPhaseCollisionInterface,
constraintSolver,
collisionConfiguration );
每秒运行六十次:
bulletDynamicsWorld.StepSimulation( (float)deltaTime, 9, 1.0F / 40.0F );
然后在退出时调用这些任意点:
Utility.SafeDispose( bulletDynamicsWorld );
Utility.SafeDispose( constraintSolver );
Utility.SafeDispose( broadPhaseCollisionInterface );
Utility.SafeDispose( collisionDispatcher );
Utility.SafeDispose( collisionConfiguration );
Utility.SafeDispose( bulletCollisionWorld ); <<< The error happens here >>>
执行突出显示的行时出现以下错误:
“运行时遇到致命错误。错误地址为0x6b1c9704,位于线程0x1378。错误代码为0xc0000005。此错误可能是CLR中的错误或不安全或不可验证的部分用户代码。此错误的常见来源包括COM-interop或PInvoke的用户封送错误,这可能会破坏堆栈。“
注意:
1)这就是所有子弹代码。没有添加碰撞对象或动态对象。
2)Utility.SafeDispose()接受IDiposable,检查空值,如果有效则调用.Dispose()。
3)语言是C#,以表明它。
4)Utility.SafeDispose(CollisionWorld)在.SafeDispose语句列表中的位置似乎没有效果。
为什么会崩溃,我该如何解决?
感谢。
答案 0 :(得分:2)
在处理bulletCollisionWorld时,它将访问broadPhaseCollisionInterface以清除由世界创建的任何冲突对。由于您在处置世界之前明确地处置了碰撞接口,因此世界将访问无效指针。
因此,解决方案是首先处理两个世界,然后再处理碰撞界面。
答案 1 :(得分:0)
DiscreteDynamicsWorld是一个碰撞世界。消除额外的碰撞世界导致没有错误;因此,问题可能是有两个碰撞世界。确实有一些全局变量。