DrawRect和NSProgressIndicator

时间:2014-04-22 21:29:58

标签: macos cocoa nsprogressindicator

我会非常简短:

我正在使用drawrect和NSBezierPath绘制线条。

要绘制这些线条,我使用for循环。

现在,由于循环需要很多秒,我尝试使用NSProgresIndicator来显示进度并在我使用的循环中更新它dispatch_async& queue .. 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]

}
               });

1 个答案:

答案 0 :(得分:1)

一般情况下,您不应该使用后台线程或队列。

有关多线程绘图的信息,请阅读本文档。跳到&#34;绘图限制&#34;

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