thanks so much lordbritishix, that fixed in five minutes, and sorry to riq.
I now have another problem, yet again EXC_BAD_ACCESS, but now zombies is returning nothing. I am using cocos2d 0.99.1 on the simulator running iOS 4.
the error only happens when ccTouchesBegan is called from inside the level class, at a certain (code included below and the point is commented).
inline b2Fixture* b2Body::GetFixtureList()
{
return m_fixtureList; // THIS IS HIGHLIGHTED IN THE DEBUGGER
}
Here is the init method inside level.mm:
-(id)initWithWorld:(b2World *)worl ThrowableArea:(int)throwableWidth Gravity: (float)gx : (float)gy{
if ((self = [super init])) {
throwWidth = throwableWidth;
self.isTouchEnabled = TRUE;
b2Vec2 grav = b2Vec2(gx, gy);
worl = new b2World(grav, true);
world = worl;
boundaryLine = [CCSprite spriteWithFile:@"Line.png"];
boundaryLine.position = ccp(throwableWidth, -310);
map = [CCTMXTiledMap tiledMapWithTMXFile:@"TheMap.tmx"];
[self addChild:map z:-1 tag:kTagBackground];
[map addChild: boundaryLine];
groundBodyDef.position.Set(0,0);
groundBody = world->CreateBody(&groundBodyDef);
boxShapeDef.shape = &groundBox;
groundBox.SetAsEdge(b2Vec2(map.position.x - (map.contentSize.width/2),(map.position.y - (map.contentSize.height/2))), b2Vec2(map.contentSize.width, (map.position.x - (map.contentSize.width/2))));
groundBody->CreateFixture(&boxShapeDef);
groundBox.SetAsEdge(b2Vec2(0, map.contentSize.height), b2Vec2(map.contentSize.width, map.contentSize.height));
groundBody->CreateFixture(&boxShapeDef);
groundBox.SetAsEdge(b2Vec2(map.contentSize.width, map.contentSize.height), b2Vec2(map.contentSize.width, 0));
groundBody->CreateFixture(&boxShapeDef);
[self schedule:@selector(tick:)];
gx = nil;
gy = nil;
throwableWidth = nil;
worl = nil;
}
return self;
}
and here is the ccTouchesBegan method inside level.mm that is making the app crash:
-(BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if (mouseJoint != NULL) return NO;
NSSet *allTouches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
if ([allTouches count] == 1) { //THE PROBLEM IS CAUSED BY ONE TOUCH THAT HAS A POSITION ON THE X AXIS LESS THAN THE THROW WIDTH
b2Vec2 locationWorld = b2Vec2(touchLocation.x, touchLocation.y);
if (touchLocation.x < throwWidth) {
b2Fixture *f;
b2Body *b = world->GetBodyList();
int i = 0;
for (CCSprite *s = [ballArray objectAtIndex:i]; b; b = b->GetNext(), f = b->GetFixtureList(), i++) { //I AM TRYING TO LOOP THROUGH ALL THE BALLS IN THE LEVEL (ALL IN BALLARRAY) AND FIND OUT IF THE TOUCH IS IN THEM
NSLog(@"Point 1 reached");
if (CGRectContainsPoint(s.textureRect ,CGPointMake(locationWorld.x, locationWorld.y))) {
NSLog(@"Point 2 reached");
mouseJointDef.bodyA = groundBody;
mouseJointDef.bodyB = bod;
mouseJointDef.target = locationWorld;
mouseJointDef.collideConnected = true;
mouseJointDef.maxForce = 1000000.0f * bod->GetMass();
mouseJoint = (b2MouseJoint *)world->CreateJoint(&mouseJointDef);
bod->SetAwake(true);
break;
}
}
}
}
return YES;
}
The code in tutorial.mm (which i am using as a test level):
-(id) init {
if ((self = [super init])) {
self.isTouchEnabled = TRUE;
level = [[Level alloc] initWithWorld:world ThrowableArea:150 Gravity:0.0f :-300.0f];
[self addChild:level];
[level addCannonBallAtPosition:100 :50];
}
return self;
}
the output from the debugger
[Session started at 2010-07-26 21:24:49 +0100.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May 5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 3469.
2010-07-26 21:24:53.937 FingerSmash Beta 2.0[3469:207] cocos2d: cocos2d v0.99.1
2010-07-26 21:24:53.938 FingerSmash Beta 2.0[3469:207] cocos2d: Using Director Type:CCDisplayLinkDirector
2010-07-26 21:24:53.971 FingerSmash Beta 2.0[3469:207] cocos2d: GL_VENDOR: Apple Computer, Inc.
2010-07-26 21:24:53.974 FingerSmash Beta 2.0[3469:207] cocos2d: GL_RENDERER: Apple Software Renderer
2010-07-26 21:24:53.975 FingerSmash Beta 2.0[3469:207] cocos2d: GL_VERSION: OpenGL ES-CM 1.1 APPLE
2010-07-26 21:24:53.975 FingerSmash Beta 2.0[3469:207] cocos2d: GL_MAX_TEXTURE_SIZE: 2048
2010-07-26 21:24:53.976 FingerSmash Beta 2.0[3469:207] cocos2d: Supports PVRTC: YES
2010-07-26 21:24:53.976 FingerSmash Beta 2.0[3469:207] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
[Switching to process 3469]
[Switching to process 3469]
2010-07-26 21:24:54.061 FingerSmash Beta 2.0[3469:207] cocos2d: Frame interval: 1
2010-07-26 21:25:00.592 FingerSmash Beta 2.0[3469:207] cocos2d: CCSpriteSheet: resizing TextureAtlas capacity from [219] to [293].
2010-07-26 21:25:00.593 FingerSmash Beta 2.0[3469:207] cocos2d: CCSpriteSheet: resizing TextureAtlas capacity from [293] to [392].
2010-07-26 21:25:00.594 FingerSmash Beta 2.0[3469:207] cocos2d: CCSpriteSheet: resizing TextureAtlas capacity from [392] to [524].
2010-07-26 21:25:00.596 FingerSmash Beta 2.0[3469:207] cocos2d: CCSpriteSheet: resizing TextureAtlas capacity from [524] to [700].
2010-07-26 21:25:05.983 FingerSmash Beta 2.0[3469:207] Point 1 reached
2010-07-26 21:25:05.984 FingerSmash Beta 2.0[3469:207] Point 1 reached
Program received signal: “EXC_BAD_ACCESS”.
(gdb)
Thankyou so much if you have read through all of that, i can't say how grateful i am.