Search code examples
iphoneiosnsthreadnsnotificationsnsnotificationcenter

why do I get "wait_fences: failed to receive reply" for this code?


why do I get "wait_fences: failed to receive reply" for this code? Is it the way I'm using notification to communicate back to the main thread?

#import "ViewController.h"

@implementation ViewController

@synthesize  alert;


#pragma mark - Background Thread Test Methods

- (void) ConfigTasksForBackground:(id)sender{
    NSLog(@"ConfigTasksForBackground - Starting");
    [NSThread sleepForTimeInterval:6];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ModelChanged" object:self];
    NSLog(@"ConfigTasksForBackground - Ending");
}

#pragma mark - Callbacks

- (void) ModelChangedHandler:(NSNotification *) notification {
    if ([[notification name] isEqualToString:@"ModelChanged"]) {
        NSLog(@"ModelChangedHandler");
        [self.alert dismissWithClickedButtonIndex:0 animated:false];
    }
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(ModelChangedHandler:) 
                                                 name:@"ModelChanged"
                                               object:nil];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.alert = [[[UIAlertView alloc] initWithTitle:@"Title" 
                                                    message:@"viewDidAppear" 
                                                   delegate:nil 
                                          cancelButtonTitle:nil
                                          otherButtonTitles:nil] autorelease];
    [alert show];
    [self performSelectorInBackground:@selector(ConfigTasksForBackground:) withObject:nil];
}



@end

Output is:

2011-11-07 15:15:42.730 test_background[6876:13603] ConfigTasksForBackground - Starting
2011-11-07 15:15:48.734 test_background[6876:13603] ModelChangedHandler
2011-11-07 15:15:49.236 test_background[6876:13603] ConfigTasksForBackground - Ending
wait_fences: failed to receive reply: 10004003

Solution

  • Here's how to get rid of the wait_fences error. Change the line where you dismiss the alertView to use animation as follows:

    [self.alert dismissWithClickedButtonIndex:0 animated:YES];
    

    I think wait_fences has something to do with view animation states with alert views but it's hard to know for sure. I do think this should eliminate the error msg though. My other answer doesn't directly get rid of the error but I still recommend it. UI actions should be done on the main thread.