我最近開始使用發佈版本(管理方案並設置從調試到發佈運行)測試我的應用程序。我注意到的是,偶爾我會在流方法中彈出以下錯誤消息,而我似乎無法找到找到錯誤的方法。這在調試模式下完美工作,但在發佈版本中,我沒有收到SIGABRT消息之外的任何通知。我也不知道如何檢查模擬器上的崩潰日誌,看看問題是什麼。下面,我附崩潰的堆棧跟蹤:從流價值暫時不可用,由於優化流
#0 0x918749c6 in __pthread_kill()
#1 0x916c0f78 in pthread_kill()
#2 0x916b1ce3 in __abort()
#3 0x916ae64a in __stack_chk_fail()
#4 0x00006d0d in -[MainViewController processMessage:len:] (_cmd=0x9ceb9, msg=0xdfd7004 "Login="User" Pass="Pass" Id="1234" PlayerId="345" Location="12,35" Color="Red" PlayerId="65" Location="180,0" Color="Blue" PlayerId="29" Location="0,200" Color="..., len=333295) at /Users/seb/Desktop/Tutorials/Networking/MainViewController.m:850
#5 0x000044b3 in -[MainViewController stream:handleEvent:] (_cmd=0x17a0410, stream=<value temporarily unavailable, due to optimizations>, eventCode=<value temporarily unavailable, due to optimizations>) at /Users/seb/Desktop/Tutorials/Networking/MainViewController.m:260
#6 0x01716501 in _inputStreamCallbackFunc()
#7 0x016e606d in _signalEventSync()
#8 0x016e67ca in _cfstream_solo_signalEventSync()
#9 0x016e5e71 in _CFStreamSignalEvent()
#10 0x016e6727 in CFReadStreamSignalEvent()
#11 0x020083ad in SocketStream::dispatchSignalFromSocketCallbackUnlocked()
#12 0x01f64191 in SocketStream::socketCallback()
#13 0x01f640a1 in SocketStream::_SocketCallBack_stream()
#14 0x016b3e44 in __CFSocketPerformV0()
#15 0x0171997f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__()
#16 0x0167cb73 in __CFRunLoopDoSources0()
#17 0x0167c454 in __CFRunLoopRun()
#18 0x0167bdb4 in CFRunLoopRunSpecific()
#19 0x0167bccb in CFRunLoopRunInMode()
#20 0x0226f879 in GSEventRunModal()
#21 0x0226f93e in GSEventRun()
#22 0x0066aa9b in UIApplicationMain()
#23 0x0000201b in main (argc=1, argv=0xbffff5e0) at /Users/seb/Desktop/Tutorials/Networking/main.m:14
Case語句:在崩潰發生在那裏的handleEvent:
case NSStreamEventHasBytesAvailable:
{
if (stream == inputStream)
{
NSLog(@"NSStreamEventHasBytesAvailable");
uint8_t buffer[4096];
unsigned int len = 0;
NSInputStream* inputstream = (NSInputStream*)stream;
len = [inputstream read:buffer maxLength:sizeof(buffer)];
// Check if our stream is still valid
if([inputstream streamError] != nil)
{
//We lost our connection to the host
NSError *theError = [stream streamError];
[self setConnectError:[NSString stringWithFormat:@"Error %i: %@",
[theError code], [theError localizedDescription]]];
break;
}
[streamIncomingData appendBytes:buffer length:len];
int processedBytes = 0;
while (true)
{
if ([streamIncomingData length] >= processedBytes + sizeof(uint32_t))
{
const char* bufferstart = ((const char*)[streamIncomingData mutableBytes]) + processedBytes;
uint32_t sz_n;
memcpy(&sz_n, bufferstart, sizeof(sz_n));
uint32_t sz_h = htonl(sz_n);
if ([streamIncomingData length] >= processedBytes + sz_h + sizeof(uint32_t))
{
[self processMessage:bufstart + sizeof(uint32_t) len:sz_h];
processedBytes += sz_h + sizeof(uint32_t);
}
else
{
break;
}
}
else
{
break;
}
}
if (processedBytes)
{
if (processedBytes < [streamIncomingData length])
{
NSMutableData *newdata = [NSMutableData dataWithBytes:[streamIncomingData bytes] + processedBytes length:[streamIncomingData length] - processedBytes];
[streamIncomingData setData:newdata];
}
else
{
[streamIncomingData setLength:0];
}
}
}
break;
}
而processMessage方法:
- (void)processMessage:(const char*)msg len:(int)len
{
NSLog(@"processMessage start (%d)", len);
{
char buffer[len + 1];
memcpy(buffer, msg, len);
buffer[len + 1] = '\0';
NSLog(@"%s", buffer);
}
NSLog(@"processMessage end");
}
任何意見非常感謝。
不知何故,你已經損壞/溢出堆棧,並沒有來自'MainViewController'流的最小代碼:handleEvent:'和'processMessage:len:'這將很難幫助你。 – Joe 2012-04-11 15:59:03
我已經更新了這個問題,以包括崩潰發生的示例代碼 – Seb 2012-04-11 16:15:01