2014-02-21 66 views
1

我測試了我的設備上運行的應用程序。但是當它提交給應用程序商店時,我會得到一個崩潰日誌。我desymbolicate它,並在我的代碼EXC_BAD_ACCESS(SIGSEGV)錯誤顯示行70錯誤。 我知道這是內存管理問題。但它不knwon什麼錯在我的代碼: 行70:崩潰日誌EXC_BAD_ACCESS(SIGSEGV)iTunes連接

69: distanceLabel = [CCLabelTTF labelWithString:@"0" fontName:@"Marker Felt" fontSize:24]; 
70: distanceLabel.anchorPoint = ccp(1, 1); 
71: distanceLabel.position = ccp(size.width/2, size.height-20); 
72: distanceLabel.color = ccBLACK; 
73: [self addChild:distanceLabel z:20]; 

而且在頭文件我宣佈distanceLabel:

@property(nonatomic,unsafe_unretained) CCLabelTTF * distanceLabel; 

那麼,什麼是我的代碼中的問題?

回答

0

由於您的變量distanceLabel設置爲__unsafe_unretained在剛剛製作完成後,其得到釋放。

//Here you create an object and assign it to the variable distanceLabel 
distanceLabel = [CCLabelTTF labelWithString:@"0" fontName:@"Marker Felt" fontSize:24]; 

//Now, since your self.distanceLabel is unretianed, 
//the object you just created has a retain count of 0 
//Therefore memory management releases the object as it 
//no longer has a retianed reference to it 
//This line is now trying to access an object that doesn't exist 
70: distanceLabel.anchorPoint = ccp(1, 1); 

如果你改變你的財產retainstrong

@property(nonatomic,strong) CCLabelTTF * distanceLabel; 

那麼你的對象將有1引用計數剛剛創建後,而不是由ARC的垃圾回收被摧毀。

編輯:更多信息。

ARC不是實時垃圾收集器。它在需要時能夠正常工作,但在您不需要時會將其留在您的設備上。由於這個原因,你的代碼是錯誤的和危險的。該視圖可以隨時發佈,因爲它的保留計數爲0.它可能會崩潰,它可能會運行。 iTunes Connect剛發現這個可能的崩潰,並說「嘿,這會毀了你的應用程序,請修復它」。

+0

很多,我明白 – user3243028

+0

我會嘗試。更愚蠢的問題是:爲什麼我的代碼不對,但它可以在我的iPhone和iPod上運行得非常好?我只能通過iTunes連接找到它。 – user3243028

+0

@ user3243028更新了我的答案,並解釋了爲什麼它在調試時沒有崩潰。 – Putz1103

0

嘗試在.H改變:

@property(nonatomic,retain) CCLabelTTF * distanceLabel; 

和.M:

@synthesize distanceLabel 

和INI方法初始化:

self.distanceLabel=[[CCLabelTTF alloc] init]; 

,然後你會影響信息到您的distanceLabel

self.distanceLabel = [CCLabelTTF labelWithString:@"0" fontName:@"Marker Felt" fontSize:24]; 
self. distanceLabel.anchorPoint = ccp(1, 1); 
self.distanceLabel.position = ccp(size.width/2, size.height-20); 
self.distanceLabel.color = ccBLACK; 
[self addChild:self.distanceLabel z:20]; 

,並在你的dealloc方法:

[self.distanceLabel release]; 

我希望這項工作

+0

但我使用ARC,所以我需要分配和釋放?以及distanceLabel和self.distanceLable之間的差異。最難的是我無法重現崩潰日誌,它在我的設備和模擬器上運行良好。 – user3243028

0

1)檢查距離標籤值; 2)用原CGPointMake替換ccp(1.0,1.0) 3)您的distanceLabel是否真的具有anchorPoint屬性?