我正在将 Libgdx 与 Box2D 结合使用。
当特定物体坠落到地面上时,我遇到了破坏关节的问题, 检测到碰撞体,然后我想破坏一些关节。 当我这样做时总是会收到错误。
我还单独测试了 destroy 方法进行测试,并且得到了相同的错误。 它是在 world.step(...) 之后调用的,对吗?
我读到一些内容,当关节在时间步长之间被破坏时,就会发生错误, 但我怎么能在世界之外做到这一点呢?
我正在使用 R.U.B.E.对于 Box2d 的事情。
这是我测试的一些代码:
scene.world.step(1.0f/scene.stepsPerSecond, scene.velocityIterations, scene.positionIterations);
if(!scene.world.isLocked()){ //to check that the joint is no locked
Joint joint1= scene.get(Joint.class, "joint1"); // read the joint from RUBE scene
scene.world.destroyJoint(joint1); //destroy it
}
这是错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006559368f, pid=5868, tid=3772
#
# JRE version: 7.0_07-b10
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.3-b01 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [gdx64.dll+0x1368f]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Jake\Downloads\AndroidDevelopment\EclipseDaten\Motor-race-desktop\hs_err_pid5868.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
AL lib: alc_cleanup: 1 device not closed
有人可以帮助我吗? :)
最佳答案
确保正确销毁关节的最佳方法是获取需要销毁的关节的引用,并在 world.step() 函数之后销毁关节。
例如
world.step(......);
if(jointToDestroy != null) {
world.destroyJoint(jointToDestroy);
jointToDestroy = null;
}
希望有帮助。
关于box2d - 破坏关节时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18118827/