Stephen_1724543
Stephen_1724543

Reputation: 71

iOS 6 : CoreAnimation: warning, deleted thread with uncommitted CATransaction

I am getting a uncommitted CATransaction warning that I can't seam to resolve. My app works fine it is doing every thing that I expect, the screen updates the label as fast as I need, it all looks good.

    Dec 10 10:40:10 my-iPhone myAppName[5967] <Warning>: CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces.

I set the CA_DEBUG_TRANSACTIONS=1 and found the following listing.

    Dec 10 10:43:45 my-iPhone myAppName[5994] <Warning>: CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
    0   QuartzCore                          0x348fc65d <redacted> + 220
    1   QuartzCore                          0x348fc541 <redacted> + 224
    2   QuartzCore                          0x348fc325 <redacted> + 24
    3   QuartzCore                          0x34900489 <redacted> + 44
    4   QuartzCore                          0x34905091 <redacted> + 456
    5   QuartzCore                          0x34904ebf <redacted> + 42
    6   QuartzCore                          0x34904e91 <redacted> + 44
    7   myAppName                       0x000d9ec1 -[MainViewController updateProgress:] + 56
    8   Foundation                          0x3a75067d <redacted> + 972
    9   libsystem_c.dylib                   0x397d6311 <redacted> + 308
    10  libsystem_c.dylib                   0x397d61d8 thread_start + 8

The code that is causing this warning looks like this :

   - (void)updateProgress:(NSString*) myLabelString
    {
    //this is updating a UILabel on the main view
    [myLabel setText:myLabelString];

    }

it is called from a for loop where I call performSelectorinBackground:

for (;;) {
   // Do stuff here to set up the info for the string

    [self performSelectorInBackground:@selector(updateProgress:) withObject:myLabelString];
    usleep(100000);
    if (stopLoop == YES) {
    // do stuff before we exit for loop            
        break;
    }

}

I have tried several things mostly with the idea of making sure that the update to myLable is complete before exiting the selector "updateProgress" , the only effect is to change the time (+56) to a larger number. I have also tried to use:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0f];    
    // edit UILabel here    
    [UIView commitAnimations];

And I tried this from a different post, but as I am not using core animations, I was not really surprised that the compiler objected to "CATransaction" as an undeclared identifier.

      [CATransaction begin];
      [CATransaction setDisableActions:YES];
      //
      [CATransaction commit];

Any suggestions on how to determine if the label update is complete? As I said the app is working I just need to clear this warning.

Upvotes: 4

Views: 6900

Answers (2)

Dalmazio
Dalmazio

Reputation: 1835

Another way of ensuring any UI drawing occurs on the main thread, as described by Stephen, is using the function dispatch_async()

// Perform all drawing/UI updates on the main thread.
dispatch_async(dispatch_get_main_queue(), ^{
    // Perform any drawing/UI updates here.
});

For a related post on the difference between dispatch_async() and performSelectorOnMainThread:withObjects:waitUntilDone: see Whats the difference between performSelectorOnMainThread and dispatch_async on main queue?

Upvotes: 1

Stephen_1724543
Stephen_1724543

Reputation: 71

This question was answered on the Developer forum. it turns out that I was doing UIKit work on a background thread.

I changed the line :

    [self performSelectorInBackground:@selector(updateProgress:) withObject:myLabelString];

To:

    [self performSelectorOnMainThread:@selector(updateProgress:) withObject:myLabelString waitUntilDone:NO];

I tried setting WaitUntilDone to YES as well and that also worked.

Upvotes: 3

Related Questions