replace @MainActor with nonisolated#38
Conversation
Summary of ChangesHello @tatsuya-ogawa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical runtime crash in the VRMExample by adjusting the concurrency isolation of a SceneKit delegate method. By marking the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a crash related to Swift Concurrency and SceneKit delegate callbacks. Marking the renderer(_:updateAtTime:) method as nonisolated is the right approach, as this delegate method is called from SceneKit's render thread, not the main actor. The change is approved. I've also added one comment suggesting a related improvement to make the code more robust by avoiding a force cast.
| extension ViewController: @MainActor SCNSceneRendererDelegate { | ||
| func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { | ||
| extension ViewController: SCNSceneRendererDelegate { | ||
| nonisolated func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { |
There was a problem hiding this comment.
Adding nonisolated here is the correct fix for the concurrency issue. Great job!
As a related improvement, the force cast as! on the next line is risky and could cause a crash. To make the code more robust, please consider changing line 53 to use optional casting:
(renderer.scene as? VRMScene)?.vrmNode.update(at: time)
tattn
left a comment
There was a problem hiding this comment.
Thank you for the bugfix! It was my mistake.
Summary
renderer(_:updateAtTime:)asnonisolatedinSCNSceneRendererDelegate.Why
On my environment, the VRMExample crashes without this change.
Notes
My understanding:
SCNSceneRendererDelegatecallbacks are invoked on SceneKit’s render thread (not the main actor). If the method is@MainActor, Swift Concurrency enforces an actor hop and the runtime crashes when the renderer calls into an isolated method. Marking itnonisolatedlets SceneKit call it safely; any UI work can still be dispatched back toMainActorinside the method if needed.