开发者

MBProgressHUD causes application to crash

开发者 https://www.devze.com 2023-01-05 16:52 出处:网络
It seems that using MBProgressHUD is causing my application to crash. Without the HUD code, the following runs just fine, but with it, it crashes:

It seems that using MBProgressHUD is causing my application to crash. Without the HUD code, the following runs just fine, but with it, it crashes:

{

    ...

    HUD = [[MBProgressHUD alloc] initWithView:self.view];

    // Add HUD to screen
    [self.view addSubview:HUD];

    // Register for HUD callbacks so we can remove it from the window at the right time
    HUD.delegate = self;

    HUD.labelText = @"Connecting";

    // Show the HUD while the provided method executes in a new thread
    [HUD showWhileExecuting:@selector(runLocalNotificationHandler) onTarget:self withObject:nil animated:YES];  

[[self navigationController] popViewControllerAnimated:YES];
}

- (void) runLocalNotificationHandler
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[self createLocalNotificationWithBug:[self tempBug]];

    [self performSelectorOnMainThread:@selector(finishedUpdatingNotifications) withObject:nil waitUntilDone:NO];

    [pool release];
}

- (void)finishedUpdatingNotifications
{

    [[self navigationController] popViewControllerAnimated:YES];
}

- (void)hudWasHidden {
    // Remove HUD from screen when the HUD was hidden
    [HUD removeFromSuperview];
    [HUD release];
}

The following debug output is produced:

gdb) continue
2010-07-02 00:07:55.224 Bugger[16796:207] >>> Entering -[HomeViewController viewDidAppear:] <<<
2010-07-02 00:07:55.225 Bugger[16796:207] <<< Leaving -[HomeViewController viewDidAppear:] >>>
2010-07-02 00:07:55.224 Bugger[16796:7007] <<< Leaving -[BugDetailViewController runLocalNotificationHandler] >>>
2010-07-02 00:07:55.226 Bugger[16796:207] >>> Entering -[BugDetailViewController prepareToolbar] <<<
2010-07-02 00:07:55.227 Bugger[16796:207] <<< Leaving -[BugDetailViewController prepareToolbar] >>>
2010-07-02 00:07:55.229 Bugger[16796:207] >>> Entering -[BugDetailViewController dealloc] <<<
[Switching to process 16开发者_StackOverflow796]
2010-07-02 00:07:55.260 Bugger[16796:207] <<< Leaving -[BugDetailViewController dealloc] >>>
[Switching to process 16796]
Program received signal:  “EXC_BAD_ACCESS”.
(gdb) 

What's going on here?

EDIT: Backtrace:

Program received signal:  “EXC_BAD_ACCESS”.
[Switching to process 23788]
(gdb) bt
#0  0x029b4a93 in objc_msgSend ()
#1  0x00000000 in ?? ()
(gdb) 


i had a similar issue with this combination of MBProgress and navigationController, for some reason looks like you can not call navigation controller actions from a selector call, you must use navigation events only in the main thread, hope this helps.


So close....

type bt<return> at that (gdb) prompt and post the backtrace.

Beyond that, my best guess is that your delegate -- the self in the above code -- is being released and deallocated without first being removed as delegate from the MBProgressHUD instance. Delegates are typically a weak reference and, thus, that would definitely cause a crash as you describe.


Ewwww... your stack has been stomped! I hate it when that happens.

Back to the best guess; is your delegate being deallocated before being removed as the delegate from the MBProgressHUD? ... have you run "Build and Analyze" on your code?

0

精彩评论

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