0
私は間違って何をしたのか分かりません。私はSIGABRTエラーを受け取り、以下のコードでforループと関係があると思います。誰かが私を助けてくれますか?前もって感謝します。cocos2dコードでSIGABRTエラーを解決しました
b2BodyDef ropeBodyDef;
ropeBodyDef.linearDamping = 0.2;
ropeBodyDef.angularDamping = 0.2;
ropeBodyDef.userData = ropeSprite;
b2Body *ropeBody;
b2Body *ropeStart = starBody;
b2MassData ropeMassData;
ropeMassData.mass = 1;
ropeBody->GetMassData(&ropeMassData);
b2DistanceJointDef ropeJointDef;
b2DistanceJoint *ropeJoint;
float dY = starBody->GetPosition().y - fittingBody->GetPosition().y;
int numSections = ceil(dY/ 55);
for (float i = 0; i < numSections - 1; i++) {
// one rope section body
ropeBodyDef.position.Set(0, starBody->GetPosition().y - dY * i/numSections);
ropeMassData.mass = 0.8 + 0.8 * i/numSections;
// rope body
ropeBody = world->CreateBody(&ropeBodyDef);
ropeFixture = ropeBody->CreateFixture(&ropeShapeDef);
[ropeSegments addObject:[NSValue valueWithPointer:ropeBody]];
// one rope section to another
ropeJointDef.Initialize(ropeStart, ropeBody, ropeStart->GetPosition(), ropeBody->GetPosition());
ropeJoint = (b2DistanceJoint*)world->CreateJoint(&ropeJointDef);
ropeJoint->SetLength(dY/numSections);
// update startpoint for next joint
ropeStart = ropeBody;
}
// final rope joint
ropeJointDef.Initialize(ropeStart, ropeBody, ropeStart->GetPosition(), ropeBody->GetPosition());
ropeJoint = (b2DistanceJoint*)world->CreateJoint(&ropeJointDef); // THIS IS THE LINE THAT I GET THE SIGABRT
ropeJoint->SetLength(dY/numSections);
[ropeSegments addObject:[NSValue valueWithPointer:fittingBody]];
[完全なコード]をご覧ください(のhttp:/ /stackoverflow.com/questions/9805620/exc-bad-access-with-cocos2d-box2d-code)視点で物事を入れるには – cocoder
どのようなもの?どのような視点?あなたはより正確な視点が必要な場合は、エラーの原因となっている正確な行を示してください。 – Lukman
完全なコードでは、私はropeBodyを含むすべてのボディを宣言しました。 – cocoder