0
我正在使用cocos2d爲iPhone製作box2d應用程序。我試圖將我的CCLayer從我的HelloWorldLayer切換到我的HomeScene,並且出現錯誤「線程1:程序接收到的信號:」EXC_BAD_ACCESS「。」當我嘗試在我的HelloWorldLayer的dealloc方法中調用[super dealloc]時,它給了我這個錯誤。請幫忙。這是我的.h和.mm如何取消分配CCLayer
@interface HelloWorldLayer : CCLayer
{
b2World *world;
Cannon *cannon1;
Cannon *cannon2;
Cannonball *cannonball1;
Cannonball *cannonball2;
float theMass;
float theMass2;
CCSprite *sunBack;
b2Vec2 cannon1Pos;
b2Vec2 cannon2Pos;
CCMenuItemSprite *pauseBut;
CCMenuItemSprite *playBut;
CCMenu *pauseMenu;
}
@property(nonatomic)b2Vec2 cannon1Pos;
@property(nonatomic)b2Vec2 cannon2Pos;
@property(nonatomic, retain)CCSprite *sunBack;
@property(nonatomic, retain)Cannon *cannon1;
@property(nonatomic, retain)Cannon *cannon2;
@property(nonatomic, retain)Cannonball *cannonball1;
@property(nonatomic, retain)Cannonball *cannonball2;
@property(nonatomic, retain)CCMenu *pauseMenu;
// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;
+(HelloWorldLayer *) sharedLayer;
-(void)createMonkeys;
-(void)restartGame;
-(void)playGame;
-(void)pauseGame;
-(CCSpriteBatchNode*)getSpriteBatch;
-(void)goToHome;
@end
這裏是我的.mm,我取消分配
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
delete world;
world = NULL;
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[cannon1 removeFromParentAndCleanup:YES];
[cannon2 removeFromParentAndCleanup:YES];
[cannonball1 removeFromParentAndCleanup:YES];
[cannonball2 removeFromParentAndCleanup:YES];
// don't forget to call "super dealloc"
[super dealloc];
}
的dealloc的你在你的圖層上調用發佈?很多Cocos對象都默認爲autorelase,所以如果你爲你的圖層調用removeChild,我相信這應該足以隱式地釋放它。 –