recursive use of an object detected which would lead to unsafe aliasing in rust
See original GitHub issueUsing rapier2d-compat version 0.7.6
// World contains some static and dynamic body
world.forEachRigidBody(body =>{
const collidersLength = body.numColliders();
for (let i = 0; i < collidersLength; i++) {
const collider = world.getCollider(body.collider(i));
drawBody(ctx, collider, body);
}
if (body.bodyType() === RAPIER.RigidBodyType.Static) {
return
}
const bodyPosition = body.translation();
const bodyMass = body.mass();
world.forEachRigidBody(otherBody => {
if (body.handle === otherBody.handle) {
return
}
const otherBodyMass = otherBody.mass();
const otherBodyPosition = otherBody.translation();
const distance = getDistance(otherBodyPosition, bodyPosition);
const forceDirection = getDirection(
otherBodyPosition,
bodyPosition
);
const forceMagnitude = getGravitationalForce(
otherBodyMass,
bodyMass,
distance
);
try {
body.applyForce(
new RAPIER.Vector2(
(Math.sin(forceDirection) * forceMagnitude) /
Math.sqrt(bodyMass),
(Math.cos(forceDirection) * forceMagnitude) /
Math.sqrt(bodyMass)
),
true
);
} catch (error) {
console.error(error);
}
})
})
This code always throws as soon as I have 2 bodies (1 static & 1 dynamic, 2 statics, 2 dynamics, whatever) with the error recursive use of an object detected which would lead to unsafe aliasing in rust
.
The error also happens with forEachRigidBodyHandle
The same code using forEachCollider works (but I wanna use forEachRigidBody because some bodies have multiple colliders)
world.forEachCollider((collider) => {
const body = world.getRigidBody(collider.parent());
drawBody(ctx, collider, body);
if (body.bodyType() === RAPIER.RigidBodyType.Static) {
return;
}
const bodyPosition = body.translation();
const bodyMass = body.mass();
world.forEachCollider((otherCollider) => {
const otherBody = world.getRigidBody(otherCollider.parent());
if (body.handle === otherBody.handle) {
return;
}
const otherBodyMass = otherBody.mass();
const otherBodyPosition = otherBody.translation();
const distance = getDistance(otherBodyPosition, bodyPosition);
const forceDirection = getDirection(
otherBodyPosition,
bodyPosition
);
const forceMagnitude = getGravitationalForce(
otherBodyMass,
bodyMass,
distance
);
try {
body.applyForce(
new RAPIER.Vector2(
(Math.sin(forceDirection) * forceMagnitude) /
Math.sqrt(bodyMass),
(Math.cos(forceDirection) * forceMagnitude) /
Math.sqrt(bodyMass)
),
true
);
} catch (error) {
console.error(error);
}
});
});
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
recursive use of an object detected which would lead ... - GitHub
Summary Hi, I am porting the "gl-matrix" to webassembly with wasm-bindgen. In "gl-matrix", we can find lots of those methods: // module vec3 ......
Read more >Recursive use of an object detected which would lead to ...
Recursive use of an object detected which would lead to unsafe aliasing in rust.
Read more >lib.rs.html -- source - Docs.rs
{ super::throw("recursive use of an object detected which would lead to \ unsafe aliasing in rust"); } #[no_mangle] pub extern fn __wbindgen_malloc(size: ...
Read more >rust - Passing mutable struct to JavaScript callback and keep ...
I'm trying to pass a struct from Rust to a JavaScript callback with ... recursive use of an object detected which would lead...
Read more >Rust: throw: closure invoked recursively or destroyed already?
SOLVED: The error message isn't clear about the rust variable being ... No idea what wasm-function[190]:27 is, would be nice to get a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, of course, you are right on that one. Completely forgot about the event callbacks 😅 I am scheduling all event updates to the next simulation step, thats why I don’t have it. I wonder why Ammo doesn’t crash, though 🤔 I guess there is some safety mechanism in place to prevent it.
@jcyuan I found out I was starting a new runtime loop before I finished the last due to async/await. So this was indeed the problem. thanks!