2013-12-18 71 views
5

我在使用SocketRocket時遇到了iOS EXC_BAD_ACCESS錯誤,我不知道如何進一步調試問題以確定問題是出在我身邊還是在SocketRocket的一側。如何調試iOS上的iOS EXC_BAD_ACCESS KERN_INVALID_ADDRESS iOS

我得到的堆棧跟蹤是:

Crashed: com.apple.main-thread 
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x2000000c 
raw 
0 libobjc.A.dylib  objc_msgSend + 5 
1 OMlearnings   SRWebSocket.m line 692 __30-[SRWebSocket _failWithError:]_block_invoke_2 
2 libdispatch.dylib _dispatch_call_block_and_release + 10 
10 UIKit    UIApplicationMain + 1136 
11 OMlearnings   main.m line 16 main 

或有時

Crashed: NSOperationQueue Serial Queue 
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0xc 
raw 
0 libobjc.A.dylib  objc_msgSend + 5 
1 OMlearnings   SRWebSocket.m line 613 -[SRWebSocket scheduleInRunLoop:forMode:] 
2 OMlearnings   SRWebSocket.m line 600 -[SRWebSocket _connect] 
3 OMlearnings   OMSRealTimeTeamDashboard.m line 157 -[OMSRealTimeTeamDashboard sendMessage:] 
4 OMlearnings   OMSRealTimeTeamDashboard.m line 171 -[OMSRealTimeTeamDashboard eventReceived:] 
5 CoreFoundation  __invoking___ + 68 
6 CoreFoundation  -[NSInvocation invoke] + 282 
7 Foundation   -[NSInvocationOperation main] + 112 
8 Foundation   -[__NSOperationInternal _start:] + 770 
14 libsystem_pthread.dylib _pthread_wqthread + 298 

我的代碼庫是非常簡單的,基本上訂閱的事件,並在隊列中執行socketrocket的sendMessage(處理併發)

[signalServices subscribe:my-event toBlock:^(NSNotification * notification) { 
    [this.queue addOperation:[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(eventReceived:) object:notification]]; 
}]; 

- (void)eventReceived: (NSNotification *)notification { 
    // ... 
    [socket send:[NSString stringWithFormat:@"%i,1,%@", currentUserId.intValue, [NSNumber numberWithInt: rate.value]]]; 
} 

我讀過使用NSZombies調試問題的人,但是m y問題很少發生,因此在問題出現之前我可能會耗盡內存。它工作正常99%的時間。

有沒有什麼需要了解iOS可以隨機崩潰使用套接字等應用程序?例如,我們啓用了後臺獲取,這可能是一些隨機崩潰的原因嗎?

謝謝!

+0

你解決了嗎? – Spail

+0

那個更新? – franck

回答

4

在堆棧跟蹤,發生在這條線

0 libobjc.A.dylib  objc_msgSend + 5 
1 OMlearnings   SRWebSocket.m line 692 __30-[SRWebSocket _failWithError:]_block_invoke_2 

EXC_BAD_ACCESS,https://github.com/square/SocketRocket/blob/master/SocketRocket/SRWebSocket.m#L692

[self.delegate webSocket:self didFailWithError:error]; 

根據該文件,https://github.com/square/SocketRocket

SRWebSocket 
(unlike NSURLConnection, SRWebSocket won't retain the delegate) 

@property (nonatomic, assign) id <SRWebSocketDelegate> delegate; 

委託屬性不被保留SRWebSocket對象,因此,如果你不保留th e委託對象,它將與懸掛指針一起崩潰。你如何對委託對象有強烈的參考?

+1

我作爲委託傳遞的對象是使用injective_register_singleton實例化的,所以它不太可能會引用 –

+1

爲什麼不在代碼中粘貼代碼? –