Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix particle rotation bug #2423

Merged
merged 3 commits into from
Nov 5, 2024
Merged

Conversation

GuoLei1990
Copy link
Member

@GuoLei1990 GuoLei1990 commented Nov 5, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • New Features

    • Enhanced instance management for the MainModule, allowing for better state handling.
  • Bug Fixes

    • Improved variable access within the MainModule to ensure consistent behavior across instances.

Copy link

coderabbitai bot commented Nov 5, 2024

Walkthrough

The pull request modifies the MainModule class in MainModule.ts by changing the visibility of the _tempVector40 variable from private static to private, transitioning it from a class-level to an instance-level variable. Additionally, the _updateShaderData method has been updated to use the instance variable this._tempVector40, which is now assigned via the copyFrom method. The overall control flow and logic of the class remain unchanged, with no new methods or alterations to existing method signatures.

Changes

File Path Change Summary
packages/core/src/particle/modules/MainModule.ts - Changed _tempVector40 visibility from private static to private.
- Updated _updateShaderData to use instance variable this._tempVector40 instead of static.

Possibly related PRs

  • Fix shader destroy memory residual #2410: The changes in the ShaderProgramPool class involve modifications to how shaders are managed, which may relate to the overall handling of particle systems and their shaders in the MainModule, particularly in how instance variables are utilized.

Suggested reviewers

  • zhuxudong
  • MrKou47

Poem

In the module where particles play,
A vector's shift brightens the day.
From static to instance, it found its way,
Each bunny now hops with less delay! 🐇✨
With shaders dancing, oh what a sight,
In the code's embrace, everything feels right!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@GuoLei1990 GuoLei1990 added the Bug Something isn't working label Nov 5, 2024
@GuoLei1990 GuoLei1990 changed the title Fix particle bug Fix particle rotation bug Nov 5, 2024
@GuoLei1990 GuoLei1990 requested a review from MrKou47 November 5, 2024 10:13
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ae0aa79 and 9a27a61.

📒 Files selected for processing (1)
  • packages/core/src/particle/modules/MainModule.ts (2 hunks)
🧰 Additional context used
🪛 Biome
packages/core/src/particle/modules/MainModule.ts

[error] 296-296: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

🔇 Additional comments (1)
packages/core/src/particle/modules/MainModule.ts (1)

15-15: Good fix: Preventing shared state issues by making _tempVector40 instance-level.

Converting _tempVector40 from static to instance-level is a good fix to prevent potential race conditions when multiple particle systems are active simultaneously.

Let's verify if there are other similar static Vector4 variables that might need the same treatment:

✅ Verification successful

✅ The _tempVector40 change is safe and no similar cases need fixing

The search results confirm this is the only temporary Vector4 used in particle system operations. Other Vector4 instances found in the codebase serve different purposes (viewport, fog parameters, atlas regions, etc.) and are correctly scoped as instance variables. This validates that the change from static to instance-level for _tempVector40 is appropriate and no other similar cases need the same treatment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for static Vector4 declarations in particle-related files
rg -U "private\s+static.*Vector4.*=\s*new\s*Vector4" --type typescript

Length of output: 107


Script:

#!/bin/bash
# Search for static Vector4 declarations in all files
rg -U "private\s+static.*Vector4.*=\s*new\s*Vector4"

# Also search for any Vector4 declarations to understand the pattern
rg -U "private.*Vector4.*=\s*new\s*Vector4"

Length of output: 1504

Comment on lines +296 to 297
const worldRotationV4 = this._tempVector40.copyFrom(worldRotation); // Maybe shaderData should support Quaternion
shaderData.setVector4(MainModule._worldRotation, worldRotationV4);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Address switch clause scoping and consider Quaternion support.

  1. The variable declaration in the switch clause should be wrapped in a block to prevent potential scoping issues.
  2. The comment suggests a technical limitation with ShaderData not supporting Quaternion directly.

Apply this fix for the switch clause scoping:

      case ParticleSimulationSpace.Local: {
        shaderData.setVector3(MainModule._worldPosition, transform.worldPosition);
        const worldRotation = transform.worldRotationQuaternion;
        const worldRotationV4 = this._tempVector40.copyFrom(worldRotation);
        shaderData.setVector4(MainModule._worldRotation, worldRotationV4);
        break;
      }

Consider adding Quaternion support to ShaderData to eliminate the need for Vector4 conversion. This would improve type safety and reduce temporary object creation.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Biome

[error] 296-296: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

@GuoLei1990 GuoLei1990 merged commit 781855d into galacean:main Nov 5, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working particle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants