Properties missing from chipmunk body on compiled JS app

I’m trying to access the shape (actually, shapeList) of a Chipmunk body, but I’m getting an undefined error. I’m using Cocos2D-JS v3.6.

So, I’ve taken the following code and ran it on chrome and in the win32-debugger of Cocos Code IDE:

for (var i in myPhysicsSprite.body) {
    console.log(i);
}

In the browser I get the following:

p
vy
vx
f
w
t
v_limit
w_limit
v_biasy
v_biasx
w_bias
space
shapeList
arbiterList
constraintList
nodeRoot
nodeNext
nodeIdleTime
m
m_inv
i
i_inv
rot
a
sanityCheck
getPos
getVel
getAngVel
isSleeping
isStatic
isRogue
setMass
setMoment
addShape
removeShape
removeConstraint
setPos
setVel
setAngVel
setAngleInternal
setAngle
velocity_func
position_func
resetForces
applyForce
applyImpulse
getVelAtPoint
getVelAtWorldPoint
getVelAtLocalPoint
eachShape
eachConstraint
eachArbiter
local2World
world2Local
kineticEnergy
activate
activateStatic
pushArbiter
sleep
sleepWithGroup

But when I run as win32 debug on Cocos Code IDE’s debugger I only get:

vx
vy
m_inv
i_inv
activate
activateStatic
applyForce
applyImpulse
destroy
getAngVel
getAngVelLimit
getAngle
getForce
getMass
getMoment
getPos
getRot
getSpace
getTorque
getVel
getVelAtLocalPoint
getVelAtWorldPoint
getVelLimit
init
initStatic
isRogue
isSleeping
isStatic
kineticEnergy
local2World
resetForces
setAngVel
setAngVelLimit
setAngle
setForce
setMass
setMoment
setPos
setTorque
setVel
setVelLimit
sleep
sleepWithGroup
updatePosition
updateVelocity
world2Local
setUserData
getUserData
eachShape
eachConstraint
eachArbiter
getHandle
setHandle

So, I can salvage this by manually adding and maintaining a property with the shapes to the PhysicsSprite directly, but I wonder if the API shouldn’t be the same between execution environments.

Hi @Wuhao, sorry for tagging you directly, but do you think this is a similar case to this one? I’m not sure where to create an issue for reporting this, could you give me a hand?

Thanks!

As the chipmunk C implementation and API is different with JS version, we have done some wrapper in JSB to adopt the APIs, but there are some cases where it’s not possible or there is no good solution. For example, the shapeList property can be directly accessed in JS version, but in C++ we can’t just access it, we must use the map function eachShape.

Although we can provide shapeList access by collecting firstly all shapes via eachShape, we think it’s not very good for performance. So we didn’t do it, we suggest you to use eachShape map function in your case.

That makes sense… But, don’t you think we could use a heads up (like, compiler warnings or something) when we are using this properties that are inconsistent between APIs so we don’t learn they don’t work cross-platform until we actually try to use them and they blow up on our face? :stuck_out_tongue:

You are right, I have created an issue:

https://github.com/cocos2d/cocos2d-x/issues/12275

Awesome, thanks!