开发者

EXC Bad Access error on iPhone Networking app

I seem to be having a problem with this general method. The problem is in the line [(TCPClient *) tcpClient connectHost: @"localhost" port:5000];

-(IBAction) asClientClicked:(id)sender{
    if(tcpClient) {
        if([tcpClient respondsToSelector:@selector(setShouldKeepRunning:)])
            [(TCPServer *)tcpServer setShouldKeepRunning: NO];
            [tcpClient release];
    } 
    tcpClient = [[TCPClient alloc] initWithDelegate:self]; 
    [(TCPClient *) tcpClient connectHost: @"localhost" port:5000];  
    mTextView.text = @"Client Waiting"; 
}

I believe it is a problem with the above allocation of tcpClient. This is the initWithDelegate method, but I don't see a problem with it.

- (TCPClient *) initWithDelegate: (id) delegate
{
self = [super init];    
[self setTheDelegate: delegate];
NSLog (@"Creating socket.");
socket = [[AsyncSocket alloc] initWithDelegate:self];
return self;
}

Thanks.

Edit: Add Crash Log

Incident Identifier: 16A2CC65-9F62-4E60-90D9-BC604484BFEA
CrashReporter Key:   92c226ba036e6bc936959f7a41f87da0716ee2bc
Hardware Model:      iPhone2,1
Process:         iPhoneSymmetricClientServer [175]
Path:            /var/mobile/Applications/88626365-3E81-4016-8FF9-6D63031CFCF9/iPhoneSymmetricClientServer.app/iPhoneSymmetricClientServer
Identifier:      iPhoneSymmetricClientServer
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2011-06-15 11:44:11.043 +0800
OS Version:      iPhone OS 4.3.3 (8J2)
Report Version:  104

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000b
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x32da1c98 objc_msgSend + 16
1   Foundation                      0x3381eae8 _NSDescriptionWithLocaleFunc + 28
2   CoreFoundation                  0x32946f74 __CFStringAppendFormatCore + 5548
3   CoreFoundation                  0x328d20b8 _CFStringCreateWithFormatAndArgumentsAux + 64
4   CoreFoundation                  0x328fdf08 _CFLogvEx + 64
5   Foundation                      0x3383a4e8 NSLogv + 56
6   Foundation                      0x3383a49c NSLog + 16
7   iPhoneSymmetricClientServer     0x000ed54c 0xe1000 + 50508
8   iPhoneSymmetricClientServer     0x000e2ff4 0xe1000 + 8180
9   CoreFoundation                  0x328d056a -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
10  UIKit                           0x32405ec2 -[UIApplication sendAction:to:from:forEvent:] + 78
11  UIKit                           0x32405e62 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
12  UIKit                           0x32405e34 -[UIControl sendAction:to:forEvent:] + 32
13  UIKit                           0x32405b86 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350
14  UIKit                           0x3240641c -[UIControl touchesEnded:withEvent:] + 336
15  UIKit                           0x32404bee -[UIWindow _sendTouchesForEvent:] + 362
16  UIKit                           0x32404568 -[UIWindow sendEvent:] + 256
17  UIKit                           0x323ed30c -[UIApplication sendEvent:] + 292
18  UIKit                           0x323ecc4c _UIApplicationHandleEvent + 5084
19  GraphicsServices                0x33433e70 PurpleEventCallback + 660
20  CoreFoundation                  0x32937a90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
21  CoreFoundation                  0x32939838 __CFRunLoopDoSource1 + 160
22  CoreFoundation                  0x3293a606 __CFRunLoopRun + 514
23  CoreFoundation                  0x328caebc CFRunLoopRunSpecific + 224
24  CoreFoundation                  0x328cadc4 CFRunLoopRunInMode + 52
25  GraphicsServices                0x33433418 GSEventRunModal + 108
26  GraphicsServices                0x334334c4 GSEventRun + 56
27  UIKit                           0x32417d62 -[UIApplication _run] + 398
28  UIKit                           0x32415800 UIApplicationMain + 664
29  iPhoneSymmetricClientServer     0x000e2cfc 0xe1000 + 7420
30  iPhoneSymmetricClientServer     0x000e2cb0 0xe1000 + 7344

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x332a8fbc kevent + 24
1   libdispatch.dylib               0x30205032 _dispatch_mgr_invoke + 706
2   libdispatch.dylib               0x3020603a _dispatch_queue_invoke + 86
3   libdispatch.dylib               0x302055ea _dispatch_worker_thread2 + 186
4   libsystem_c.dylib               0x32c9658a _pthread_wqthread + 258
5   libsystem_c.dylib               0x32c96bbc start_wqthread + 0

Thread 2 name:  WebThread
Thread 2:
0   libsystem_kernel.dylib          0x332a5c00 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x332a5758 mach_msg + 44
2   CoreFoundation                  0x329382b8 __CFRunLoopServiceMachPort + 88
3   CoreFoundation                  0x3293a562 __CFRunLoopRun + 350
4   CoreFoundation                  0x328caebc CFRunLoopRunSpecific + 224
5   CoreFoundation                  0x328cadc4 CFRunLoopRunInMode + 52
6   WebCore                         0x3114b27e RunWebThread(void*) + 382
7   libsystem_c.dylib               0x32c9530a _pthread_start + 242
8   libsystem_c.dylib               0x32c96bb4 thread_start + 0

Thread 0 crashed with ARM Thread State:
    r0: 0x1e57c08c    r1: 0x331de008      r2: 0x34428bf4      r3: 0x00000000
    r4: 0x00000003    r5: 0x34428bf4      r6: 0x00000000      r7: 0x2fedd1c0
    r8: 0x2fedd2a4    r9: 0x003fffff     r10: 0x00000000     r11: 0x00000000
    ip: 0x3f4ed4e8    sp: 0x2fedd1a4      lr: 0x34327aef      pc: 0x338aac98
  cpsr: 0x200f0030

Binary Images:
   0xe1000 -    0xf0fff +iPhoneSymmetricClientServer armv7  <d582def3249f306ea428b4dff34a96dd> /var/mobile/Applications/88626365-3E81-4016-8FF9-6D63031CFCF9/iPhoneSymmetricClientServer.app/iPhoneSymmetricClientServer
0x2fee0000 - 0x2ff05fff  dyld armv7  <bb9bfc7d242331d29a79adf7ef7aaa18> /usr/lib/dyld
0x30b28000 - 0x30b5ffff  Security armv7  <6599f42a910b3b31a0e1d98c883d61cb> /System/Library/Frameworks/Security.framework/Security
0x30baf000 - 0x30bb8fff  CoreVideo armv7  <ea847e6dba2d36b1826b255c73b39539> /System/Library/Frameworks/CoreVideo.framework/CoreVideo
0x30bf3000 - 0x30bfffff  SpringBoardServices armv7  <c68262667ac8397a949ce4e92dfec7db> /System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices
0x30c00000 - 0x30c05fff  libnotify.dylib armv7  <9d7198e91de9386a9e5ea43608a66a57> /usr/lib/system/libnotify.dylib
0x30c4c000 - 0x30c4dfff  libsystem_network.dylib armv7  <39bf0f48bd8539169a77f8f61cdcd4c9> /usr/lib/system/libsystem_network.dylib
0x30d08000 - 0x30d15fff  libdispatch.dylib armv7  <9a0511ad5ebc3db898f1f49ed1a73d34> /usr/lib/system/libdispatch.dylib
0x30ddc000 - 0x30df5fff  libRIP.A.dylib armv7  <4825c3e392983aba947eca06555e4480> /System/Library/Frameworks/CoreGraphics.framework/Resources/libRIP.A.dylib
0x30e4c000 - 0x30e57fff  libz.1.dylib armv7  <ac706bee36593dc683fd5a96a389d72e> /usr/lib/libz.1.dylib
0x30fe1000 - 0x30fe1fff  libsystem_sandbox.dylib armv7  <f47c01d627853b328e088b3fdd08e87d> /usr/lib/system/libsystem_sandbox.dylib
0x30fe2000 - 0x31041fff  libBLAS.dylib armv7  <0b36b2272aa33a8c9aa22d99c89d7189> /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/libBLAS.dylib
0x31042000 - 0x31042fff  libdnsinfo.dylib armv7  <21415179ffa03f949fa8cc851c6c31c7> /usr/lib/system/libdnsinfo.dylib
0x31150000 - 0x31151fff  libdyld.dylib armv7  <41a7b5e5d9983449ab33affed0f635ad> /usr/lib/system/libdyld.dylib
0x31152000 - 0x31187fff  AddressBook armv7  <3f2071a77bc134cd82065eef90d4082f> /System/Library/Frameworks/AddressBook.framework/AddressBook
0x311da000 - 0x31212fff  IOKit armv7  <80ae313ad69d3363935c88e51a11862d> /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
0x31216000 - 0x31218fff  libAccessibility.dylib armv7  <d55f1553d14831a2a5435ae27ef75ef4> /usr/lib/libAccessibility.dylib
0x31239000 - 0x3123bfff  IOMobileFramebuffer armv7  <683f321680763e519d61541170ba2133> /System/Library/PrivateFrameworks/IOMobileFramebuffer.framework/IOMobileFramebuffer
0x31380000 - 0x31484fff  JavaScriptCore armv7  <61a94142e2d23dafa2964190dd46e9e3> /System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore
0x314aa000 - 0x314b0fff  liblockdown.dylib armv7  <14c89b7346433c1f8675f454531f6ca3> /usr/lib/liblockdown.dylib
0x314b1000 - 0x314b6fff  libsystem_dnssd.dylib armv7  <c7cfe523e2d73521abc01587313ef730> /usr/lib/system/libsystem_dnssd.dylib
0x314b7000 - 0x314b7fff  Accelerate armv7  <7d5ad465049136afaa1f0d89aac600bc> /System/Library/Frameworks/Accelerate.framework/Accelerate
0x31505000 - 0x315aefff  libxml2.2.dylib armv7  <5538d3f2c7d83b88b06168488fe6326b> /usr/lib/libxml2.2.dylib
0x31987000 - 0x3198bfff  libcache.dylib armv7  <d2f7fd2a352b3cd59c564be34b53cf80> /usr/lib/system/libcache.dylib
0x3198c000 - 0x31993fff  libbz2.1.0.dylib armv7  <0a082e1d475432959ba93aa3dbf7fb31> /usr/lib/libbz2.1.0.dylib
0x31a42000 - 0x31a6bfff  MobileCoreServices armv7  <57fef84bdc17301d8bf53ba0fb967fe6> /System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices
0x31a6f000 - 0x31a9efff  SystemConfiguration armv7  <1d73b8a159363f96bb9c039655c5eae6> /System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration
0x31a9f000 - 0x31ad2fff  AppSupport armv7  <0217468bd9f839229a47910b7816b3d5> /System/Library/PrivateFrameworks/AppSupport.framework/AppSupport
0x31c4e000 - 0x32259fff  WebCore armv7  <07941e59d0a33f94802c16c76238fddf> /System/Library/PrivateFrameworks/WebCore.framework/WebCore
0x322b1000 - 0x32405fff  AudioToolbox armv7  <6619c8c13f8d328e923e797fa8d0df23> /System/Library/Frameworks/AudioToolbox.framework/AudioToolbox
0x32408000 - 0x32529fff  CoreGraphics armv7  <65f6c8701b563542820a26b0dfc4f6a4> /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics
0x3252d000 - 0x3252dfff  libCVMSPluginSupport.dylib armv7  <42d8aa2a31843a6e8bfff745644a7ba5> /System/Library/Frameworks/OpenGLES.framework/libCVMSPluginSupport.dylib
0x32e3f000 - 0x32e41fff  libgcc_s.1.dylib armv7  <a2631ac302f4310dae8367939e16b7c2> /usr/lib/libgcc_s.1.dylib
0x32ee0000 - 0x32ee4fff  libGFXShared.dylib armv7  <a0772a32cd8b3b9194bb0c29807c1c5b> /System/Library/Frameworks/OpenGLES.framework/libGFXShared.dylib
0x32ef2000 - 0x3327ffff  UIKit armv7  <c271b78464d93cb7bf28c6e49df293ba> /System/Library/Frameworks/UIKit.framework/UIKit
0x33282000 - 0x332c8fff  CoreTelephony armv7  <af7d1e770e5a3ffd8834a57fb5d40557> /System/Library/Frameworks/CoreTelephony.framework/CoreTelephony
0x33319000 - 0x33320fff  AggregateDictionary armv7  <ab9777b39e8e3026ad64dc90323cad7e> /System/Libr开发者_JAVA百科ary/PrivateFrameworks/AggregateDictionary.framework/AggregateDictionary
0x333cb000 - 0x334b0fff  CoreFoundation armv7  <a8444f997111304c9571b3ff974b769c> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
0x334b1000 - 0x334fbfff  libstdc++.6.dylib armv7  <b2cac408951c3f3c9ba3cf563e54ce81> /usr/lib/libstdc++.6.dylib
0x33659000 - 0x33698fff  libSystem.B.dylib armv7  <33dcf9a403ae3fd5971d6030ada2fcab> /usr/lib/libSystem.B.dylib
0x3370c000 - 0x3374efff  CoreAudio armv7  <c972fd5f8e89333ca680b9a33587f896> /System/Library/Frameworks/CoreAudio.framework/CoreAudio
0x3376b000 - 0x337ecfff  libsystem_c.dylib armv7  <a7077267b6743ed3bbdd86d4380c75d9> /usr/lib/system/libsystem_c.dylib
0x3380e000 - 0x33813fff  liblaunch.dylib armv7  <f5ccc8234aea3ebd9a88bd37f0fa23ae> /usr/lib/system/liblaunch.dylib
0x338a8000 - 0x3396cfff  libobjc.A.dylib armv7  <6b51e76fde9f381bb7b3bc5badbfee3a> /usr/lib/libobjc.A.dylib
0x3397d000 - 0x339ecfff  ProofReader armv7  <6d843c6aecdd37ae84baa40af8ad7e65> /System/Library/PrivateFrameworks/ProofReader.framework/ProofReader
0x33a50000 - 0x33b3dfff  libiconv.2.dylib armv7  <f4146ce07e3031ea8a81fa5516fd77d0> /usr/lib/libiconv.2.dylib
0x33bc8000 - 0x33c19fff  libsqlite3.dylib armv7  <8a41cc6a6d9332308bc415d27577fd24> /usr/lib/libsqlite3.dylib
0x33d9f000 - 0x33db6fff  libsystem_kernel.dylib armv7  <a06ec84e53bf32098b63c0caebdb45b6> /usr/lib/system/libsystem_kernel.dylib
0x33e62000 - 0x33e65fff  IOSurface armv7  <ad50e71624583d06b891344d832f9b08> /System/Library/PrivateFrameworks/IOSurface.framework/IOSurface
0x33ec3000 - 0x33f00fff  CoreText armv7  <fb6a72faec2330c4b2cd33c2e9c59588> /System/Library/Frameworks/CoreText.framework/CoreText
0x33f38000 - 0x33f44fff  GraphicsServices armv7  <ff78a9636e933f0dbd222f8d26209788> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
0x33f8f000 - 0x33facfff  libsystem_info.dylib armv7  <48016be86e3f3cd9aeee1c6590e1ac6f> /usr/lib/system/libsystem_info.dylib
0x34086000 - 0x3408afff  AssetsLibraryServices armv7  <e1cbfe599c96369ca4bdb0dd99d3cd9f> /System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
0x34109000 - 0x34117fff  OpenGLES armv7  <5a76beaeaa013f0cbf16e5cb154598ab> /System/Library/Frameworks/OpenGLES.framework/OpenGLES
0x34231000 - 0x34269fff  libCGFreetype.A.dylib armv7  <ccea634795153164a681f0f311f4461d> /System/Library/Frameworks/CoreGraphics.framework/Resources/libCGFreetype.A.dylib
0x34325000 - 0x34444fff  Foundation armv7  <09ff368178c5321c9715b9c8d491d53f> /System/Library/Frameworks/Foundation.framework/Foundation
0x34445000 - 0x34447fff  MobileInstallation armv7  <94b6d6c5d9883175af26764567528127> /System/Library/PrivateFrameworks/MobileInstallation.framework/MobileInstallation
0x34460000 - 0x34475fff  libresolv.9.dylib armv7  <e92cfbb83f7b330db19181e797bb3f7b> /usr/lib/libresolv.9.dylib
0x34476000 - 0x3447bfff  MobileKeyBag armv7  <8c35c090bc373cb181fc26b961b8dba5> /System/Library/PrivateFrameworks/MobileKeyBag.framework/MobileKeyBag
0x35ecf000 - 0x35eeffff  PrintKit armv7  <e5a01ca9083a36afacc08611a398e2ad> /System/Library/PrivateFrameworks/PrintKit.framework/PrintKit
0x35fe6000 - 0x36095fff  QuartzCore armv7  <ef9632c9781f3101916b65e9faae1579> /System/Library/Frameworks/QuartzCore.framework/QuartzCore
0x36142000 - 0x36201fff  CFNetwork armv7  <b09e0d53de9f3bc8bde494780f3cdd4f> /System/Library/Frameworks/CFNetwork.framework/CFNetwork
0x364c3000 - 0x364c4fff  libsystem_blocks.dylib armv7  <ccc041df3de73eafb7a59e74cdb1702b> /usr/lib/system/libsystem_blocks.dylib
0x364e8000 - 0x364edfff  libcopyfile.dylib armv7  <e57c2b9054b831d9a37119baaa4947cb> /usr/lib/system/libcopyfile.dylib
0x366dc000 - 0x366ddfff  libremovefile.dylib armv7  <e8858a499d663e6a9e3c188521273cc1> /usr/lib/system/libremovefile.dylib
0x366de000 - 0x366ebfff  libbsm.0.dylib armv7  <0a1e2bb78d5138419ecad8ba0fe42fdd> /usr/lib/libbsm.0.dylib
0x369ce000 - 0x36a23fff  libvDSP.dylib armv7  <0221caba81a235c5a896a835e2aac047> /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/libvDSP.dylib
0x36a24000 - 0x36d11fff  libLAPACK.dylib armv7  <b855d60dac01310495453bddfd004f0d> /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/libLAPACK.dylib
0x36d1b000 - 0x36d57fff  libGLImage.dylib armv7  <9d97699e44ee3651ba4ac37e5adec35b> /System/Library/Frameworks/OpenGLES.framework/libGLImage.dylib
0x36e06000 - 0x36eb7fff  WebKit armv7  <eb9a0d69c64b3127b2bffd71641add3b> /System/Library/PrivateFrameworks/WebKit.framework/WebKit
0x36f21000 - 0x36f22fff  CoreSurface armv7  <7b83cd757da73e6e826693c29296d3fa> /System/Library/PrivateFrameworks/CoreSurface.framework/CoreSurface
0x37039000 - 0x3703cfff  libmacho.dylib armv7  <43311c113a9d3182b7d007129819f029> /usr/lib/system/libmacho.dylib
0x3703d000 - 0x37157fff  libicucore.A.dylib armv7  <bada0c2725bb31a483d5adf9aaf1f8df> /usr/lib/libicucore.A.dylib
0x37158000 - 0x37158fff  vecLib armv7  <0c60cd0a60f43d2791d36cb357d30e3c> /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/vecLib
0x3718e000 - 0x37223fff  ImageIO armv7  <d520e3241d1130e8ac1375ee0f2c1095> /System/Library/Frameworks/ImageIO.framework/ImageIO
0x372a1000 - 0x372c0fff  Bom armv7  <b178e3efb4d733c694bd5a55e57a314f> /System/Library/PrivateFrameworks/Bom.framework/Bom

Edit 2:

     -       (BOOL) connectHost: (NSString *) host port: (UInt16) port
     {
        @try
        {
    NSError *err;

    [socket connectToHost:host onPort:port error:&err];
    NSLog (@"Could not connect. Error domain %@, code %d (%@).",
           [err domain], [err code], [err localizedDescription]);
    if( err == nil) {
        NSLog (@"Connecting to %@ port %u.", host, port);
        return YES;
    }
    else
        NSLog (@"Could not connect. Error domain %@, code %d (%@).",
               [err domain], [err code], [err localizedDescription]);
}
@catch (NSException *exception)
{
    NSLog ([exception reason]);
}   
return NO;
  }


Your problems is in these lines,

if([tcpClient respondsToSelector:@selector(setShouldKeepRunning:)])
    [(TCPServer *)tcpServer setShouldKeepRunning: NO];
[tcpClient release];

You are checking whether tcpClient is capable of responding to setShouldKeepRunning: and later invoking it on tcpServer. As it is crashing, tcpServer is not nil and cannot respond to setShouldKeepRunning:. You probably meant it for tcpClient. Adjust code as necessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜