0
私はクラスTileMapを持っています。それはメモリにレベルをロードし、幅と高さを読み取ります。私は自動解放でこのクラスを呼び出すときにでも - >プログラムは、私が書くとき、別のクラスでの.mautoreleaseのクラッシュ(cocos2d)
#import "TileMap.h"
@implementation TileMap
@synthesize tileMap = _tileMap;
@synthesize width = _width;
@synthesize height = _height;
- (void) dealloc
{
//[_tileMap release];
self.tileMap = nil;
[super dealloc];
}
-(void) loadMapWithLVL: (NSString *)lvl
{
[self.tileMap release];
NSString *lvl_new = [NSString stringWithFormat:@"%@.tmx",lvl];
CCLOG(@"Reload TileMap to %@", lvl_new);
self.tileMap = [[CCTMXTiledMap tiledMapWithTMXFile:lvl_new] retain];
self.width = _tileMap.mapSize.width;
self.height = _tileMap.mapSize.height;
}
- (id)init
{
self = [super init];
if (self) {
CCLOG(@"Init TileMap");
self.tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"1lvl.tmx"];
self.width = _tileMap.mapSize.width;
self.height = _tileMap.mapSize.height;
CCLOG(@"size map in init %0.2f %0.2f", _width, _height);
}
return self;
}
@end
での.h
#import "cocos2d.h"
@interface TileMap : NSObject
{
CCTMXTiledMap *_tileMap;
float _width, _height;
}
@property (nonatomic, retain) CCTMXTiledMap *tileMap;
@property (readwrite) float width;
@property (readwrite) float height;
-(void) loadMapWithLVL : (NSString *)lvl;
@end
で
をクラッシュ:
TileMap *testmap = [[[TileMap alloc] init] autorelease];
float testg = testmap.width;
CCLOG(@"size map %0.2f", testg);
私はクラッシュしている。しかし、私が書くとき:
TileMap *testmap = [[TileMap alloc] init];
float testg = testmap.width;
CCLOG(@"size map %0.2f", testg);
[testmap release]
私はクラッシュしていません。なぜこうなった?