osx - CoreAnimation warning when updating NSProgressIndicator via a block executed on main queue -


i have following scenario exporting core data entities json , displaying progress bar while doing so.

sometimes, after sheet progress bar dismissed when export completed, follwing warning console message:

coreanimation: warning, deleted thread uncommitted catransaction; set ca_debug_transactions=1 in environment log backtraces.

appdelegate.m

//  appdelegate.m  - (void)exportasjson:(id)sender; {     nssavepanel *savepanel = [nssavepanel savepanel];      [savepanel beginsheetmodalforwindow:[self window] completionhandler:^(nsinteger result) {         wmjsonexportoperation *operation = nil;          if (result == nsfilehandlingpanelokbutton)         {             [_progressindicator setdoublevalue:0];             operation = [[wmjsonexportoperation alloc] init];              // setprogresscallbackblock             [operation setprogresscallbackblock: ^(double progress) {                 [[nsoperationqueue mainqueue] addoperationwithblock:^                  {                      [_progressindicator setdoublevalue: progress];                  }];             }];              // setexportcompletionblock             [operation setexportcompletionblock:^(nsdata *data, nserror *error) {                 // insert code here save data disk                 [_window endsheet:_exportprogresssheet];             }];              [_window beginsheet:_exportprogresssheet completionhandler:^(nsinteger result) {                 nslog(@"exportprogresssheet completionhandler executed");             }];              nsoperationqueue *queue;             queue = [[nsoperationqueue alloc] init];             [queue addoperation:operation];         }      }]; } 

wmjsonexportoperation.m, subclass of nsoperation:

- (void)main; {     nserror *error = nil;     nsdata *data = nil;      // illustrating problem:     (int i=1; i<=10; i++) {         sleep(1);         [self progresscallbackblock](i * 10);     }      [self exportcompletionblock](data, error); }  @end 

so first question is: warning, should care?

the second question is, how avoid warning. there questions on describing similar problems, suggested solution manipulate nsprogressindicator main queue. isn't doing code:

    // setprogresscallbackblock     [operation setprogresscallbackblock: ^(double progress) {         [[nsoperationqueue mainqueue] addoperationwithblock:^          {              [_progressindicator setdoublevalue: progress];          }];     }]; 

after investigating message further setting ca_debug_transactions environment variable, found, problem not message send nsprogressindicator, closing of sheet, did indeed trigger queue main queue.

so change fixes problem:

[_window endsheet:_exportprogresssheet]; 

becomes:

[[nsoperationqueue mainqueue] addoperationwithblock:^    {       [_window endsheet:_exportprogresssheet];    }]; 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -