thisguy
thisguy

Reputation: 71

Fix fatal iOS crash

`I am AdHoc testing an app that lets you login to an apache server, take pics , and upload them as jpeg thumbs to a UIScrollView. From there you can tap the thumb to view it fullscreen. The app runs perfectly on iPad, but when I tap a thumb to view it fullscreen on iPhone 4 the app crashes/freezes and the compiler highlights the following line of code with a

    Thread 1: EXC_BAD_ACCESS(code=1, address=0xf6c04478)

    //code compiler highlights simultaneously when the app freezes on iPhone 4
    [api commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"stream", @"command", IdPhoto,@"IdPhoto", nil] onCompletion:^(NSDictionary *json) {

***EDIT***
After the debugger displays (lldb) and I type 'bt' this is what is displayed:

    * thread #1: tid = 0x5a399, 0x3931598e libobjc.A.dylib`lookUpImpOrForward + 46, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xf6c04478)
    frame #0: 0x3931598e libobjc.A.dylib`lookUpImpOrForward + 46
    frame #1: 0x39315956 libobjc.A.dylib`_class_lookupMethodAndLoadCache3 + 34
    frame #2: 0x3931a8b8 libobjc.A.dylib`_objc_msgSend_uncached + 24
    frame #3: 0x2ea9b5a8 CoreFoundation`+[__NSDictionaryM __new:::::] + 536
    frame #4: 0x2ea9e2f0 CoreFoundation`-[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 240
    frame #5: 0x2eaa2dcc CoreFoundation`+[NSDictionary dictionaryWithObjectsAndKeys:] + 372
  * frame #6: 0x0002c07c faunna`-[StreamPhotoScreen viewDidLoad](self=0x17f86c70, _cmd=0x319d0af3) + 200 at StreamPhotoScreen.m:8
    frame #7: 0x313814aa UIKit`-[UIViewController loadViewIfRequired] + 518
    frame #8: 0x31381268 UIKit`-[UIViewController view] + 24
    frame #9: 0x3150d36a UIKit`-[UINavigationController _startCustomTransition:] + 634
    frame #10: 0x3142ad62 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 418
    frame #11: 0x3142ab6c UIKit`-[UINavigationController __viewWillLayoutSubviews] + 44
    frame #12: 0x3142ab04 UIKit`-[UILayoutContainerView layoutSubviews] + 184
    frame #13: 0x3137cd58 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 380
    frame #14: 0x30ffa62a QuartzCore`-[CALayer layoutSublayers] + 142
    frame #15: 0x30ff5e3a QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 350
    frame #16: 0x30ff5ccc QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
    frame #17: 0x30ff56de QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 230
    frame #18: 0x30ff54ee QuartzCore`CA::Transaction::commit() + 314
    frame #19: 0x30fef21c QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
    frame #20: 0x2eb2b254 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
    frame #21: 0x2eb28bf8 CoreFoundation`__CFRunLoopDoObservers + 284
    frame #22: 0x2eb28f3a CoreFoundation`__CFRunLoopRun + 730
    frame #23: 0x2ea93ebe CoreFoundation`CFRunLoopRunSpecific + 522
    frame #24: 0x2ea93ca2 CoreFoundation`CFRunLoopRunInMode + 106
    frame #25: 0x33999662 GraphicsServices`GSEventRunModal + 138
    frame #26: 0x313e014c UIKit`UIApplicationMain + 1136
    frame #27: 0x0003f6dc faunna`main(argc=1, argv=0x27de1d14) + 108 at main.m:14
(lldb) 

This is streamphotoscreen in its entirety...

#import "StreamPhotoScreen.h"
#import "API.h"
@implementation StreamPhotoScreen
@synthesize IdPhoto;
-(void)viewDidLoad {
API* api = [API sharedInstance];
//load the caption of the selected photo
[api commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"stream", @"command", IdPhoto,@"IdPhoto", nil] onCompletion:^(NSDictionary *json) {
    //show the text in the label
    NSArray* list = [json objectForKey:@"result"];
    NSDictionary* photo = [list objectAtIndex:0];
    lblTitle.text = [photo objectForKey:@"title"];
}];
//load the big size photo
NSURL* imageURL = [api urlForImageWithId:IdPhoto isThumb:NO];
[photoView setImageWithURL: imageURL];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
@end

Why is the app crashing? Could it be the iPhone itself?

Upvotes: 1

Views: 1369

Answers (1)

zaph
zaph

Reputation: 112873

The crash is happening in the viewDidLoad method of StreamPhotoScreen. One of a couple of things is happening, 1. You have code in that method that is causing the crash. 2. There is a connection problem with the view. 3. Other. If you have any code in the method add the method's code to the question. If not carefully check all the connections, delegates and class name in the view.

It may be using APIs that are iOS5 and above but that usually is easy to spot in the crash back trace. You need to set breakpoints and step the debugger. Debugging is a skill set that is as important as writing the code, at least early in and for many.

Run the static analyzer: Menu : Product : Analyzer. Click the twisties to see the execution path and fix all warnings. Do the same in Xcode 7, it is supposed to have even better diagnostics.

Upvotes: 0

Related Questions