物理引擎报错

版本:1.9.1-rc
逻辑:子弹组件中update里判断超过一定时间(如0.5秒)后,设置节点active为false。
同时,组件还做碰撞监听回调,在onBeginContact方法中设置节点active为false,没有其他逻辑。

结果运行中,当子弹碰撞到其他刚体时,经常会报错:

ERROR: TypeError: undefined is not an object (evaluating ‘a.body’), location: src/jsb_polyfill.js:11823:74
STACK:
emit@src/jsb_polyfill.js:11823:74
_onBeginContact@src/jsb_polyfill.js:12088:30
Step@[native code]
update@src/jsb_polyfill.js:11934:7
ERROR: TypeError: undefined is not an object (evaluating ‘a.body’), location: src/jsb_polyfill.js:11823:74
STACK:
emit@src/jsb_polyfill.js:11823:74
_onPreSolve@src/jsb_polyfill.js:12099:12
Step@[native code]
update@src/jsb_polyfill.js:11934:7
ERROR: TypeError: undefined is not an object (evaluating ‘a.body’), location: src/jsb_polyfill.js:11823:74
STACK:
emit@src/jsb_polyfill.js:11823:74
_onPostSolve@src/jsb_polyfill.js:12105:7
Step@[native code]
update@src/jsb_polyfill.js:11934:7
ERROR: TypeError: undefined is not an object (evaluating ‘a.body’), location: src/jsb_polyfill.js:11823:74
STACK:
emit@src/jsb_polyfill.js:11823:74
_onEndContact@src/jsb_polyfill.js:12093:7
DestroyBody@[native code]
_removeBody@src/jsb_polyfill.js:12046:14
__destroy@src/jsb_polyfill.js:12669:44
pushDelayEvent@src/jsb_polyfill.js:11916:16
_destroy@src/jsb_polyfill.js:12644:47
onDisable@src/jsb_polyfill.js:12617:14
disableComp@src/jsb_polyfill.js:3586:27
_deactivateNodeRecursively@src/jsb_polyfill.js:11642:39
activateNode@src/jsb_polyfill.js:11673:32
set@src/jsb_polyfill.js:16750:64
bulletBoom@src/project.js:1149:10
update@src/project.js:1159:16
anonymous
invoke@src/jsb_polyfill.js:3535:13
updatePhase@src/jsb_polyfill.js:3608:26
callback@src/jsb_polyfill.js:21736:39

补充一下:
用浏览器测试是不报错的,但是用模拟器和原生机器测试都会报错

@jjyinkailejj 是不是物理引擎的对象绑定有问题?返回了原生的 sgNode

请问这个问题有什么原因导致呢?有什么修复方法吗?

有解决办法么

有在看么 = =

this.colliderA = b2contact.GetFixtureA().collider;
this.colliderB = b2contact.GetFixtureB().collider;

b2contact.GetFixtureA() 有值。。 但有的时候 有collider 有的时候 没有collider。。 没有的时候 就挂了。

你好我们的线上物理项目卡顿,定位不到原因,方便定位下吗

go to /Applications/CocosCreator.app/Contents/Resources/engine/bin/.cache/ios/jsb_polyfill.dev.js

then find the function below: === >>
//Add scope Check null collider --> worked for me
PhysicsContact.prototype.emit = function(contactType) {
var func;
switch (contactType) {
case ContactType.BEGIN_CONTACT:
func = “onBeginContact”;
break;

     case ContactType.END_CONTACT:
      func = "onEndContact";
      break;

     case ContactType.PRE_SOLVE:
      func = "onPreSolve";
      break;

     case ContactType.POST_SOLVE:
      func = "onPostSolve";
    }
    //Add scope Check null collider --> worked for me
    if(this.colliderA == null || this.colliderA == undefined) return; 
    if(this.colliderB == null || this.colliderB == undefined) return;
    var colliderA = this.colliderA;
    var colliderB = this.colliderB;

物理引擎还有个问题,在碰撞回调里无法创建新的刚体,新建的刚体质量都是零,必须延迟一帧才行。