我会很简短:
我正在使用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]
}
});
最佳答案
通常,您不应该在后台线程或队列上绘图。
请阅读本文档以获取有关多线程绘图的信息。跳到“绘图限制”
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html