SceneKit - Threads - What to do on which thread?

前端 未结 2 1379
深忆病人
深忆病人 2020-12-31 05:24

When using SceneKit, the update method:

func renderer(aRenderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval)    

is not called on

2条回答
  •  旧巷少年郎
    2020-12-31 05:28

    The documentation for SCNSceneRendererDelegate here and here seems to have nothing to say about threads, and yet the delegate is clearly invoked on a secondary thread, at least on macOS 10.11.6 (and apparently whatever version of iOS you are on). One might reasonably suppose that if this had posed any kind of issue for SceneKit the documentation would by now have been revised accordingly.

    Apple's Fox sample code has a renderer delegate which makes many changes to the scene seemingly without regard to what any other thread might be up to, and from this one might reasonably assume that doing so poses no issue for SceneKit. (It also seems as if Fox is driven almost entirely out of the renderer delegate, so perhaps it has little reason to worry about multiple threads.)

    This may be possible due to SceneKit's automatic per-thread transactions as documented here. It sounds as if you can do whatever you want whenever you want as long as you don't require visible effects any earlier than your return to the run loop. This is the only documentation I could find about SceneKit that mentions threads in any substantive way.

    The above all said, this could be a huge issue for your own logic. The good news is that you noticed your delegate is being invoked on a secondary thread. If you didn't notice this early in your project, the bad news is you might have a lot of work to do.

    Threads may be synchronized in a variety of ways. You're probably best off using Apple's modern facilities for doing so, but there is also a variety of other, older approaches you may want to consider if you find yourself in a tight spot.

提交回复
热议问题