0

私は非常に短くなります:

drawrect と NSBezierPath を使用して線を描いています。

これらの線を描くために、for ループを使用しています。

現在、ループには数秒かかるため、NSProgresIndicator を使用して進行状況を表示し、dispatch_async とキューを使用したループ内で更新しようとしています。ProgressIndicator は更新されますが、何も描画されません。使用しない場合ラインが描画されるキューですが、サイクルの最後にインジケーターが更新されます。

私は何を間違っていますか?

エラー:

<Error>: CGContextRestoreGState: invalid context 0x0. 
This is a serious error. 
This application, or a library it uses, is using an invalid context
and is thereby 
contributing to an overall degradation of system stability and reliability.
 This notice is a courtesy: please fix this problem.
 It will become a fatal error in an upcoming update.

// SAMPLE OF CODE
dispatch_queue_t myQueue = dispatch_queue_create("my queue", NULL);
dispatch_async(myQueue, ^
               {
for (int i = 1; i <= 200; i++) {

    dispatch_async(dispatch_get_main_queue(), ^{
        [istance set_progress:i]; 
//This sets the progress, but bezierPath doesn't work
    });


//Bezier already alloc & init
[my_path moveToPoint....]
[my_path lineToPoint....]
[my_path stroke]

}
               });
4

1 に答える 1

1

一般に、バックグラウンド スレッドまたはキューで描画するべきではありません。

マルチスレッド描画については、このドキュメントをお読みください。「描画制限」へスキップ

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html

于 2014-04-25T20:58:43.263 に答える