Skip to content

replace @MainActor with nonisolated#38

Merged
tattn merged 1 commit intotattn:mainfrom
tatsuya-ogawa:feature/nonisolated
Jan 24, 2026
Merged

replace @MainActor with nonisolated#38
tattn merged 1 commit intotattn:mainfrom
tatsuya-ogawa:feature/nonisolated

Conversation

@tatsuya-ogawa
Copy link
Copy Markdown
Contributor

@tatsuya-ogawa tatsuya-ogawa commented Jan 24, 2026

Summary

  • Mark renderer(_:updateAtTime:) as nonisolated in SCNSceneRendererDelegate.

Why

On my environment, the VRMExample crashes without this change.

Notes

My understanding: SCNSceneRendererDelegate callbacks 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 it nonisolated lets SceneKit call it safely; any UI work can still be dispatched back to MainActor inside the method if needed.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 renderer(_:updateAtTime:) method as nonisolated, the change ensures that SceneKit's rendering thread can invoke this callback directly and safely, preventing an actor hop that previously led to application instability. This improves the robustness and correct behavior of the rendering pipeline.

Highlights

  • Concurrency Isolation: The renderer(_:updateAtTime:) method within the SCNSceneRendererDelegate extension has been explicitly marked as nonisolated. This change removes the @MainActor isolation from the method, allowing it to be called directly by SceneKit's render thread without an actor hop.
  • Crash Prevention: This modification resolves a crash observed in the VRMExample, which occurred when the renderer(_:updateAtTime:) callback was implicitly or explicitly isolated to the @MainActor, leading to runtime issues when invoked from SceneKit's non-main rendering thread.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)

Copy link
Copy Markdown
Owner

@tattn tattn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the bugfix! It was my mistake.

@tattn tattn merged commit 5b43f46 into tattn:main Jan 24, 2026
3 checks passed
@tatsuya-ogawa tatsuya-ogawa deleted the feature/nonisolated branch January 24, 2026 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants