Albert Català
Albert Català

Reputation: 2044

How to avoid "CoreAnimation warning deleted thread with uncommitted CATransaction" if NOT using CoreAnimation

Just in the appdelegates, applicationDidBecomeActive. I create and start a thread, this thread waits an asynchronous download and then save data:

 - (void)applicationDidBecomeActive:(UIApplication *)application
    {
              // begins Asynchronous download data (1 second):
               [wsDataComponents updatePreparedData:NO];

               NSThread* downloadThread = [[NSThread alloc] 
                  initWithTarget:self 
                        selector: @selector (waitingFirstConnection) 
                          object:nil];
               [downloadThread start];
        }

then

-(void)waitingFirstConnection{    

    while (waitingFirstDownload) {
      // Do nothing ...  Waiting a asynchronous download, Observers tell me when
      // finish first donwload
    }

    // begins Synchronous download, and save data (20 secons)
    [wsDataComponents updatePreparedData:YES];

    // Maybe is this the problem ?? I change a label in main view controller 
    [menuViewController.labelBadgeVideo setText:@"123 videos"];

    // Nothig else, finish and this thread is destroyed
}

In the Organizer console, when finished, I am getting this warning:

CoreAnimation: warning, deleted thread with uncommitted CATransaction;

Upvotes: 3

Views: 6000

Answers (3)

Dalmazio
Dalmazio

Reputation: 1835

Another way of ensuring any UI drawing occurs on the main thread, as described by Andrew, is using the method performSelectorOnMainThread:withObject:waitUntilDone: or alternatively performSelectorOnMainThread:withObject:waitUntilDone:modes:

- (void) someMethod
{
    […]

    // Perform all drawing/UI updates on the main thread.
    [self performSelectorOnMainThread:@selector(myCustomDrawing:)
                           withObject:myCustomData
                        waitUntilDone:YES];

    […]
}

- (void) myCustomDrawing:(id)myCustomData
{
    // 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: 3

Albert Català
Albert Català

Reputation: 2044

I have found the problem: Is changing a label in menuViewController

In this thread, i use a isntance variable than is de menuViewController:

[menuViewController.labelBadgeVideo setText:@"123 videos"];

If i comment this line no warning appears

(Now I have to find out how to change this label without warning)

Upvotes: 0

Andrew Madsen
Andrew Madsen

Reputation: 21383

This error is most commonly seen when using UIKit UI API on a non-main thread. You don't have to be directly using Core Animation to see this. All UIViews are backed by a Core Animation layer, so Core Animation is in use whether you're interacting directly with it or not.

There's not enough code in your question to identify the exact problem, but the fact that you're using multithreading is a clue that your problem is as I've described. Are you updating your UI after the download is complete and/or the data is saved? If so, you need to move the UI update back to the main thread/queue. This is easier if you use GCD instead of NSThread:

// download is finished, save data
dispatch_async(dispatch_get_main_queue(), ^{
    // Update UI here, on the main queue
});

Upvotes: 8

Related Questions