Objective-C 和 Quartz Composer; [qcView PauseRendering] 导致 Bad_Access

发布于 2024-10-15 19:49:43 字数 1178 浏览 1 评论 0原文

提前致谢。

我有一个 Quartz Composer 视图(下面的 qcView),并以随机方向移动图像(蚂蚁的图像,如果您想知道代码),直到它发现它位于 QCView 中间的“家”。暂停渲染是必要的,这样我们才能看到蚂蚁一寸一寸地移动;没有它,蚂蚁只会出现在它的“家”。

while([self distance] > acceptableOffset){
    [qcView pauseRendering];
    [self moveTowardsDestination:@"home"];
    [qcView resumeRendering];
}

这对于一只蚂蚁来说效果非常好。

当我在方程中添加另一只蚂蚁时,我使用一个调度队列和两个块。

    dispatch_async(queue, ^{
        [theAnt findCenter];
    });

    dispatch_async(queue, ^{
        [otherAnt findCenter];
    });

当这段代码运行时,两个阿姨同时跑到她们家——这正是我们正在寻找的行为。但是,当我停止执行并再次构建时,我立即从 [qcView PauseRendering] 方法中的某个位置获取 Exc_Bad_Access。清洁后构建它将完美地再运行一次。 删除pauseRendering和resumeRendering后,蚂蚁将立即出现在他们的家中。

显然,QCView的pauseRendering方法有一个本地数组,它不断地增长和收缩,通过单个QCView和访问它的多个块,您可以看到问题的根源。

我研究了 QCView文档并且似乎无法在那里找到灵感;关于暂停渲染的文档很少。虽然我确信你们中没有人尝试过像这样愚蠢的事情,但我希望有人有实际修改 QCView 的经验,并且能够为我指明正确的方向(呃......读“任何!”)方向。

[编辑:我尝试过“while (![qcView isPausedRendering])”的变体,如果有帮助的话。]

thanks in advance.

I have a Quartz Composer View (qcView below) and move an image (of an ant, if you were wondering of the code) in a random direction until it finds it's 'home' in the middle of the QCView. The pauseRendering is necessary so that we can see the ant move inch by inch; without it the ant will just appear at it's 'home'.

while([self distance] > acceptableOffset){
    [qcView pauseRendering];
    [self moveTowardsDestination:@"home"];
    [qcView resumeRendering];
}

This works perfectly fine for a single ant.

When I add another ant to the equation, I use a dispatch queue and two blocks.

    dispatch_async(queue, ^{
        [theAnt findCenter];
    });

    dispatch_async(queue, ^{
        [otherAnt findCenter];
    });

When this code is run, the two aunts scurry to their home's concurrently - the exact behavior we're looking for. However, when I stop the execution and build again, I immediately get a Exc_Bad_Access from somewhere within the [qcView pauseRendering] method. After a Clean & Build it will work perfectly for one more run.
With the pauseRendering and resumeRendering removed, the ants will instantly appear at their home.

Apparently there is an array local to the QCView pauseRendering method which is constantly growing and shrinking, and with the single QCView and the multiple blocks accessing it you can see the root of the problem.

I've researched the QCView documentation and can't seem to find inspiration there; the documentation on pauseRendering is minimal. While I'm sure none of you has tried something as silly as this I'm hoping someone would have experience with pragmatically modifying a QCView and would be able to point me in the right (err... read "ANY!") direction.

[Edit: I've tried variations of "while (![qcView isPausedRendering])", if that helps.]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神妖 2024-10-22 19:49:43

您确定 QCView 实例确实支持并发吗?

可能性极小。如果您正在处理来自单独线程或队列的视图(甚至非并发地来自后台队列/线程),您很可能违反了 QCView 的并发规则。

我怀疑您必须从主线程操作视图,或者至少一次从一个线程操作视图。

(不幸的是,我找不到这方面的任何具体信息)。

Are you sure that QCView instances actually support concurrency?

Highly unlikely. If you are mucking w/the views from separate threads or queues -- even non-concurrently from a background queue/thread -- you are quite likely violating the concurrency rules of the QCView.

I'd suspect that you must manipulate the view from the main thread or, at the least, from one thread at a time.

(I couldn't find any specific information on this, unfortunately).

流绪微梦 2024-10-22 19:49:43

解决了。

事实证明我大大高估了这个问题。使用 Go 图的简单修复

     usleep(10000);

这最初是在代码中,但它被替换为dispatch_suspend()。在暂停之前进行睡眠,即可实现所需的活动。

如果有人遇到类似问题,请随时给我发电子邮件。

Solved it.

Turns out I was vastly overestimating the problem. Simple fix of using

     usleep(10000);

Go figure.

This was originally in the code, however it was substituted in favor of dispatch_suspend(). With the sleep on the line just before the suspension, the desired activity is achieved.

If anyone encounters similar problems feel free to email me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文