我正在使用cocos2d创建一个iPhone应用程序,每次我尝试从函数返回一个变量,我在下面的代码中得到运行时错误...
GB2ShapeCache *cache = [GB2ShapeCache sharedShapeCache];
//EXC_BAD_ACCESS run time error here
*eggFixture = [cache addFixturesToBody:body forShapeName:@"egg3"];
我不知道我做错了什么......这是addFixturesToBody的代码...
-(b2Fixture) addFixturesToBody:(b2Body*)body forShapeName:(NSString*)shape
{
BodyDef *so = [shapeObjects objectForKey:shape];
assert(so);
b2Fixture *Fixi;
FixtureDef *fix = so->fixtures;
while(fix)
{
Fixi = body->CreateFixture(&fix->fixture);
fix = fix->next;
}
return *Fixi;
}
在这里我定义了我的变量eggFixture
b2Fixture *eggFixture;
这是我稍后尝试使用b2fixture eggFixture的地方
for(pos = _contactListener->_contacts.begin();
pos != _contactListener->_contacts.end(); ++pos) {
MyContact contact = *pos;
if ((contact.fixtureA == locations.platformFixture && contact.fixtureB == eggFixture) ||
(contact.fixtureA == eggFixture && contact.fixtureB == locations.platformFixture)) {
NSLog(@"Ball hit bottom!");
}
}
有任何帮助吗?谢谢你:)
答案 0 :(得分:0)
看起来body
是零。当身体为零时,它肯定会崩溃:
Fixi = body->CreateFixture(&fix->fixture);
This article has some tips for debugging issues like EXC_BAD_ACCESS.