2012-03-22 2 views
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]]; 

답변

0

당신은 ropeBody 아래의 첫 번째 줄을 선언하고 당신은 이미 그 가치 초기화하고 할당하지 않고 그 위에 메소드를 호출/:

b2Body *ropeBody; <-- declare here 
b2Body *ropeStart = starBody; 
b2MassData ropeMassData; 
ropeMassData.mass = 1; 
ropeBody->GetMassData(&ropeMassData); <-- uh, ropeBody is null or rubbish pointer 
+0

가 [전체 코드 (HTTP를 살펴주세요 /stackoverflow.com/questions/9805620/exc-bad-access-with-cocos2d-box2d-code) 관점에 물건을 넣으십시오. – cocoder

+0

무엇이 있습니까? 어떤 관점? 보다 나은 원근감을 원한다면 어떤 정확한 선이 오류를 일으키는 지 표시해야합니다. – Lukman

+0

전체 코드에서 나는 ropeBody를 포함하여 모든 몸체를 선언했습니다. – cocoder

관련 문제