Rapier3d physic bug

needle engine 4.16
unity 6000.0.69f1

Uncaught Error: recursive use of an object detected which would lead to unsafe aliasing in rust
at B.wbg.__wbindgen_throw (rapier3d.CxarogEY.js:1:73756)
at 005fccd2:0x16c706
at 005fccd2:0x16c722
at 005fccd2:0x135745
at L.coTranslation (rapier3d.CxarogEY.js:1:8214)
at MI.translation (rapier3d.CxarogEY.js:1:127835)
at Gr.syncPhysicsBody (index-FW1STYyO.js:1723:6293)
at Gr.syncObjects (index-FW1STYyO.js:1723:5008)
at Gr.postStep (index-FW1STYyO.js:1723:3780)
at Qe.internalUpdatePhysics (index-FW1STYyO.js:905:4507)

Hello oot4chi, thank you for bringing this issue to our attention. The error you’re encountering indicates a potential issue with recursive object handling in the Rapier3D physics engine, which could be due to a stale reference or a circular reference when updating physics bodies.

To assist you better, let’s gather some more details and proceed with troubleshooting:

  1. Describe the Issue: Can you provide a brief description of what you are trying to achieve and how this error might be related to your intended functionality?
  2. Repro Steps: Have you been able to reproduce this error in a simplified scenario? If so, could you share the steps needed to reproduce the issue?
  3. Code Example: Do you have any code that triggers this error? If possible, sharing a snippet would be very helpful.
  4. GameObject Configuration: How are your GameObjects configured in Needle Engine? Specifically, are any GameObjects or components set up in a way that could cause a circular reference?
  5. Scene Layout: Is there a specific scene layout or structure that might be contributing to this issue?
  6. Network State: Are you using the networking features in Needle Engine? If so, how are you managing object state synchronization?

Regarding the specific error message:

  • “Uncaught Error: recursive use of an object detected which would lead to unsafe aliasing in rust”:
    • This suggests that there is an attempt to access a reference that is already being used within a recursive context or that there might be a circular reference in your objects’ states.
    • Ensure that there are no circular references in the object hierarchy when setting up the physics bodies.
    • Check if the Rigidbody or Collider components are correctly instantiated and configured.

Troubleshooting Steps

  1. Verify Prerequisites:

    • Ensure you have followed the getting-started guidelines for Needle Engine 4.16 and Unity 6000.0.69f1.
  2. Clean Installation:

    • Run a clean installation by selecting your Needle Engine component, holding Alt, and then clicking Clean Install.
  3. Check Component Setup:

    • Ensure that the Rigidbody and Collider components are correctly initialized and there are no circular dependencies in their setup.
  4. Scene Structure:

    • Check the scene for any complex structures or interactions that might be causing the issue. This includes checking the hierarchy for any duplicate or interdependent object references.
  5. Update Physics Components:

    • Verify that the GryncPhysicsBody function is properly configured and called only when necessary. Ensure that the GameObject’s state is correctly managed during updates.

Simplified Example

Here is a simplified example to help you understand how to properly set up physics components:

import { Behaviour, Rigidbody, Collider } from "@needle-tools/engine";

export class PhysicsExample extends Behaviour {
    start() {
        // Ensure the GameObject has no existing Rigidbody or Collider
        const rb = this.gameObject.addNewComponent(Rigidbody);
        rb.mass = 10;
        rb.drag = 0.5;
        rb.angularDrag = 0.5;

        // Ensure the Collider is added to the exact same GameObject, not to a child or parent.
        const collider = this.gameObject.addNewComponent(Collider);
        collider.shape = "box";  // or "sphere", "capsule", etc.
        collider.size = [2, 2, 2];  // or appropriate size for your shape

        console.log("Physics enabled!");
        console.log("Rigidbody:", rb);
        console.log("Collider:", collider);
    }
}

Additional Resources

If you can provide more details based on the above questions, I can help you more specifically resolve the issue.

Sources: Needle Engine API (67%), Needle Engine API (61%), Needle Engine API (59%), Needle Engine API (59%), Needle Engine API (57%), Needle Engine Docs (57%), Needle Engine API (56%), Needle Engine Docs (55%), Needle Engine Docs (55%)

1 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

use this.context.physics.engine?.raycast();

Hi, please provide a reproducible bugreport so we can look at the error. Otherwise we’re not able to help.

I’m not sure what caused it—possibly a caching issue. However, after updating to version 4.16.3, the caching problem no longer occurs.
Note: The only physics feature I’m using is Raycast with BoxCollider.

What caching problem are you refering to? The rapier error can happen if somewhere in your project a Object3D with a Collider or Rigidbody gets invalid values (e.g. NaN values) as far as I know.


again

Hi without more info or a reproduction we’re not able to help. See my previous reply: Rapier3d physic bug - #6 by Marcel_Wiessler1

The errors you share are most likely happening because of what I said previously.


console.warn(“Error running physics step”, { timestep: this.world.timestep }, e);

Based on the information you’ve provided, you’re seeing an error related to physics in Needle Engine, specifically during the physics step. The error message is logged with console.warn, indicating issues with running the physics step. The error occurs within a frame step of the physics simulation, which might be due to invalid state values such as NaN (Not a Number).

Given that the issue might be related to cached invalid values in your physics bodies, here are some steps you can take:

  1. Check Values: Verify that your BoxCollider’s properties such as position, rotation, and dimensions are correct and do not contain invalid values like NaN.

  2. Debugging: Add more detailed logging around the raycast operation to inspect the state of your colliders just before running the step. This can help identify when and why invalid values are being passed to the physics engine.

  3. Revert Changes: If you made recent changes to your scene or code, try reverting them to see if this resolves the issue. This can help isolate the problematic change.

  4. Update: Ensure you’re using the latest version of Needle Engine. Sometimes, these kinds of issues are resolved in newer releases.

If you can provide more specific details about where and how the invalid values are occurring, it would be easier to pinpoint the exact cause.

Would you like to walk through any of these steps in more detail or need help with any specific part of debugging this issue?

Sources: Needle Engine API (63%), Needle Engine API (60%), Needle Engine API (60%), Needle Engine Docs (59%), Needle Engine Docs (59%), Needle Engine Docs (58%), Needle Engine Docs (57%), Needle Engine API (57%), Needle Engine API (57%)

1 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

error in needle engine line
chunk-QF3ZUY34.js?v=56e8b093:34210 Frame #4340
Error: recursive use of an object detected which would lead to unsafe aliasing in rust
at I3.wbg.__wbindgen_throw (rapier-STYG565K.js?v=56e8b093:2599:13)
at 005fccd2:0x16c706
at 005fccd2:0x16c722
at 005fccd2:0xdf5cf
at _H.castRay (rapier-STYG565K.js?v=56e8b093:105:20)
at mI.castRay (rapier-STYG565K.js?v=56e8b093:3614:91)
at _ag.castRay (rapier-STYG565K.js?v=56e8b093:4474:28)
at _RapierPhysics.raycast (@needle-tools_engine.js?v=56e8b093:929:59)
at _GameManager.shoot (GameManager.ts:147:58)
at _GameManager.update (GameManager.ts:88:18)

const hit = (_a2 = this.world) == null ? void 0 : _a2.castRay(ray, maxDistance, solid, options == null ? void 0 : options.queryFilterFlags, options == null ? void 0 : options.filterGroups, void 0, void 0, (c) => {

Hi oot4chi,

Thank you for reaching out with the specific error details. It seems you are encountering an issue in Needle Engine related to the physics engine (Rapier Physics) where there is a recursive use of an object that would lead to unsafe aliasing in Rust.

To better understand and address this issue, could you provide more context about your scene setup or the code where this error occurs? Specifically:

  1. Scene and Object Setup: Can you describe the objects involved in the raycasting operation? Are there any objects with complex transformations or overlapping volumes?

  2. Raycast Configuration: Are there any custom query filter flags or filter groups being used in the castRay method? If so, how are they configured?

  3. Reproduction Steps: Can you provide a minimal reproducible example that leads to this error? This would help in isolating the issue and testing potential fixes.

  4. Code Structure: Can you share the full code snippet from your GameManager.ts where the shoot method is defined? Understanding the sequence of operations leading up to the castRay method might give us more insight into the problem.

  5. Environment Details: Are you using any specific plugins or integrations (like NEKeyboardEvent, NEPointerEvent, etc.) that might be affecting the physics simulation?

  6. Dependencies: Are there any recent updates or changes in your dependencies (@needle-tools/engine, three.js, etc.) that could have introduced this issue?

Based on the error message, it seems that there is a problem with the data structure being used in the physics engine’s raycasting functionality. If you could share the relevant parts of your code and more details about your scene setup, we can work through this further.

Here is a general approach to debugging this issue:

  1. Check for Recursive References: Ensure that no object in your scene graph has a recursive reference that could lead to aliasing issues. This can happen if an object references itself or another object in a way that the physics engine does not handle properly.

  2. Examine Query Filters and Filter Groups: Verify that the queryFilterFlags and filterGroups are correctly set up and do not lead to infinite recursion in the physics engine.

  3. Validate Object States: Ensure that all physics object states (position, rotation, etc.) are valid and do not contain invalid values such as NaN.

If you can provide any of the above details, it would greatly help in pinpointing the exact cause of the issue and suggesting a potential fix.

Best regards,

Qwen

Sources: Needle Engine API (64%), Needle Engine API (63%), Needle Engine Docs (61%), Needle Engine Docs (61%), Needle Engine Docs (61%), Needle Engine API (61%), Needle Engine API (59%), Needle Engine Docs (59%), Needle Engine Docs (59%)

0 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

Error creating collider “Good_Duck_3”
Error: Error: recursive use of an object detected which would lead to unsafe aliasing in rust
at I3.wbg.__wbindgen_throw (rapier-STYG565K.js?v=56e8b093:2599:13)
at 005fccd2:0x16c706
at 005fccd2:0x16c722
at 005fccd2:0xd1c8d
at _O.createCollider (rapier-STYG565K.js?v=56e8b093:576:86)
at qg.createCollider (rapier-STYG565K.js?v=56e8b093:5026:236)
at _ag.createCollider (rapier-STYG565K.js?v=56e8b093:4432:27)
at _RapierPhysics.createCollider (@needle-tools_engine.js?v=56e8b093:1377:30)
at _RapierPhysics.addBoxCollider (@needle-tools_engine.js?v=56e8b093:1145:10)
at _BoxCollider.onEnable (chunk-QF3ZUY34.js?v=56e8b093:50285:64)

GameObject.setActive(this.currentDuck, true);

Hi oot4chi,

Thank you for providing the error details. Based on the stack trace and error message, it appears that the issue is related to recursive use of an object, which leads to unsafe aliasing in Rust. This often indicates a problem with circular references or improper object ownership in the Rapier physics engine.

Here are some steps to debug and potentially resolve this issue:

  1. Check Circular References:

    • Ensure that no GameObjects have circular references. Circular references can cause issues because the physics engine needs to ensure proper ownership and lifetime tracking.
  2. Object Activation and Deactivation:

    • Review your code for any GameObjects that are actively set to true but not properly deactivated (SetActive(false)). Ensure objects are deactivated when they are no longer needed to avoid lingering references.
    • Example:
      GameObject.setActive(this.currentDuck, false);
      
  3. Object Ownership:

    • Verify that the ownership of your Collider objects is managed correctly. If a Collider is owned by another object, make sure that the owner object is properly initialized and destroyed when necessary.
    • For instance, if you have a Rigidbody attached to the GameObject, ensure both are properly managed:
      const collider = BoxCollider.Create(...);
      rigidbody.AddCollider(collider);
      
  4. Debugging Logs:

    • Add more logging to trace the lifecycle of the GameObject and its Colliders. This can help identify where the circular reference might be occurring.
    • Example:
      console.log('Creating Duck Collider');
      const collider = BoxCollider.Create(...);
      console.log('Adding Collider to Rigidbody');
      rigidbody.AddCollider(collider);
      
  5. Review Recent Changes:

    • If the issue started after a recent change, review that change to identify potential sources of the circular reference.
    • If possible, revert the change temporarily to see if the issue persists.
  6. Consult Documentation:

If you provide more details about the GameObject hierarchy and the specific lifecycle states of the objects involved, I can offer more targeted advice.

Does this help? Any additional details or questions you can provide would be very useful.

Sources: Needle Engine API (61%), Needle Engine API (60%), Needle Engine API (58%), Needle Engine API (58%), Needle Engine API (57%), Needle Engine API (57%), Needle Engine API (57%), Needle Engine API (56%), Needle Engine API (55%)

1 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

maybe error when setactive gameObject with collider

Hello oot4chi,

It sounds like you might be experiencing issues related to the activation and deactivation of Game Objects with colliders. Here are a few clarifying questions to help diagnose the problem:

  1. GameObject State Transition:

    • Can you confirm whether the GameObject.setActive(this.currentDuck, true) line is inside the onEnable or onDisable lifecycle hooks of the Collider component?
  2. Collider Configuration:

    • Have you checked the configuration of the BoxCollider component for the GameObject named “Good_Duck_3”? Specifically, verify that there are no NaN values in its properties (position, scale, etc.).
  3. Physics World Initialization:

    • Ensure that the physics world has been properly initialized before you attempt to create or modify colliders. You can do this by calling NEEDLE_ENGINE_MODULES.RAPIER_PHYSICS.MODULE.initialize().

If you could provide more details or a small reproducible example, it would be easier to pinpoint the exact cause of the issue. Additionally, if you have access to the error log or more context around the usage of the BoxCollider, please share that as well.

Thank you for your cooperation!

Sources: Needle Engine API (63%), Needle Engine API (59%), Needle Engine API (59%), Needle Engine API (57%), Needle Engine API (57%), Needle Engine API (57%), [Needle Engine API](RapierPhysics | Needle Engine (56%), Needle Engine API (56%), Needle Engine API (54%)

0 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

I’m trying to understand how colliders work with GameObjects.

Why isn’t a collider “persisted” with the object after disabling it?

When I disable a GameObject using SetActive(false) and then enable it again, it seems like the collider has to be recreated or reinitialized every time.

Is this expected behavior?
How does the engine handle colliders internally when a GameObject is deactivated and reactivated?

Thanks!

Hi,

At the moment this is what happens:

  • When the collider component gets disabled (or the gameobject set to visible: false which is what SetActive(false) does) then the Rapier collider gets removed from the Physics world.

  • When the collider becomes active again (gets enabled) then the Rapier collider gets created and added back to the physics world.

Disabling just the collider instead of fully removing would probably be more ideal but I’m not sure how much gain it would bring. Do you have a scene where many physics objects are added/removed which causes performance drops?

Thanks for the explanation.

I’ve noticed that sometimes when re-enabling a GameObject, the collider fails to be created properly.

This doesn’t happen consistently, but in some cases the collider seems to not exist or doesn’t interact with physics as expected after being reactivated.

Is this a known issue or could it be related to how the collider is re-added to the physics world?

Hello, it’s not a known issue, no.

But if you want to test I’ve changes this in the latest Needle Engine alpha 4.17.0-alpha.3 (that’s the Unity package version) which only disables the Rapier collider shapes when the Collider component is disabled - so they’re not removed completely anymore here.

1 Like