많은 box2d 본문을 만든 후 세계에 추가하면 EXEC_BAD_ACCESS 오류가 발생하여 EXEC_BAD_ACCESS 오류가 발생합니다. 본문을 만드는 방법은 다음과 같습니다.주기 내에서 Box2d 본문 만들기
충돌이 발생하는 위치for(CXMLElement *node in obstaclesArr)
{
b2BodyDef nObstacleBody;
b2Body *obsBody;
CCSprite *obstacle;
obstacle = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%@.png",[[node attributeForName:@"body"]stringValue]]];
NSString *strX = [[node attributeForName:@"x"]stringValue];
NSString *strY = [[node attributeForName:@"y"]stringValue];
float x;
float y;
x = [strX floatValue];
y = [strY floatValue];
obstacle.tag = E;
obstacle.position = ccp(x,y);
[self addChild:obstacle z:9];
nObstacleBody.type = b2_staticBody;
nObstacleBody.position.Set(x/PTM_RATIO, y/PTM_RATIO);
nObstacleBody.userData = obstacle;
obsBody = world->CreateBody(&nObstacleBody);
[[GB2ShapeCache sharedShapeCache]addFixturesToBody:obsBody forShapeName:[[node attributeForName:@"body"]stringValue]];
[obstacle setAnchorPoint:[[GB2ShapeCache sharedShapeCache]anchorPointForShape:[[node attributeForName:@"body"]stringValue]]];
}
그리고 여기이있다 :
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
if (b->GetUserData() != NULL) {
//Synchronize the AtlasSprites position and rotation with the corresponding body
CCSprite *myActor = (CCSprite*)b->GetUserData();
myActor.position = CGPointMake(b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);//<-- crashes in this line
myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
}
}
내가 왜 충돌되는 등의 단서가 없다, 누가 좀 도와주세요 수 있습니까?
덕분에 많은 라즈도 내가, 내가 초기화에서 호출되는 한 방법 수준을 구축하고 충돌을 피하는 또 다른 방법을 발견하고, init 메소드 내부에서 크래시가 발생하지 않지만 솔루션을 사용하는 것이 더 깔끔하고 깨끗합니다. 고마워요! – Usul