私はこのようなAsyncSocketを持っています。NSMutableStringデータ追加エラー
- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
NSString *message = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
[data getBytes:&tdata];
if (tdata > 5) {
if(bheader){
if(!charS){
if([message isEqualToString:@"S"]){
CMSG = message;
charS=YES;
}
}
else{
NSMutableString *tmp = [[NSMutableString alloc] initWithString:@""];
[tmp appendString:CMSG]; <<<<< This is code error at loop 2,
[tmp appendString:message]; the first loop success but second is fail
CMSG = tmp;
[tmp release];
}
}
else{
if (message){
cmessage = [[NSString alloc]initWithFormat:@"%@%@",cmessage,message] ;
}
else
NSLog(@"Error converting received data into UTF-8 String");
cdata++;
if(cdata==idata) {
msgComplete=YES;
}
}
if (msgComplete) {
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:cmessage forKey:kNotificationMessage];
[notificationCenter postNotificationName:kNotification object:self userInfo:userInfo];
[email protected]"";
[email protected]"";
msgComplete=NO;
bheader=YES;
cdata=0;
charS=NO;
[cmessage release];
}
}
[sock readDataToLength:1 withTimeout:-1 tag:0];
}
このコードは[tmp appendString:CMSG];
スレッド1の第2ループで失敗:プログラムは、信号 "SIGABRT" を受信
このエラーを修正する方法は?
ありがとうございます。
「ループ」と言いますが、このコードにループはありません。それはループ内で実行されていますか? –
デバッガでこれを実行している場合は、通常、SIGABRTには例外とスタックトレースが付属しています。 _ *あまりにも*それらを含めるには非常に問題がありますか? – Andrew
これはメソッドにループしています:) – user752846