Skip to content

Scaling bodies/shapes with Jolt Physics sometimes results in "Failed to correctly scale ..." errors #107986

Open
@mihe

Description

@mihe

Tested versions

  • Reproducible in: 4.4.stable
  • Reproducible in: 4.5.dev [30456ba]

System information

N/A

Issue description

When using Jolt Physics as the 3D physics engine, you can sometimes find yourself in situations where you'll see a bunch of error spam in the Output panel saying things like:

ERROR: modules/jolt_physics/objects/jolt_shaped_object_3d.cpp:72 - Failed to correctly scale body 'MyStaticBody:<StaticBody3D#2307823585269>'. A scale of (1.000000, 1.000000, 1.208180) is not supported by Jolt Physics for this shape/body. The scale will instead be treated as (1.069393, 1.069393, 1.069393)

or...

ERROR: modules/jolt_physics/objects/jolt_shaped_object_3d.cpp:97 - Failed to correctly scale shape at index 0 in body 'MyStaticBody:<StaticBody3D#2307823585269>'. A scale of (1.000000, 1.000000, 0.828577) is not supported by Jolt Physics for this shape/body. The scale will instead be treated as (0.942859, 0.942859, 0.942859).

The reason for this is a deliberate runtime error check in the Jolt Physics module, as seen here:

#define ERR_PRINT_INVALID_SCALE_MSG(m_scale, m_valid_scale, m_msg) \
if (unlikely(!JoltShape3D::is_scale_valid(m_scale, valid_scale))) { \
ERR_PRINT(vformat("%s " \
"A scale of %v is not supported by Jolt Physics for this shape/body. " \
"The scale will instead be treated as %v.", \
m_msg, m_scale, valid_scale)); \
} else \
((void)0)

#define JOLT_ENSURE_SCALE_VALID(m_shape, m_scale, m_msg) \
if (true) { \
const Vector3 valid_scale = JoltShape3D::make_scale_valid(m_shape, m_scale); \
ERR_PRINT_INVALID_SCALE_MSG(m_scale, valid_scale, m_msg); \
(m_scale) = valid_scale; \
} else \
((void)0)

if (scale != Vector3(1, 1, 1)) {
Vector3 actual_scale = scale;
JOLT_ENSURE_SCALE_VALID(result, actual_scale, vformat("Failed to correctly scale body '%s'.", to_string()));
result = JoltShape3D::with_scale(result, actual_scale);
}

This was put in to make clear when the user is (often by mistake) scaling something (in the editor or at runtime) in ways that will cause the collision detection to produce results that may differ significantly from what the accompanying mesh or other visual aid shows.

Invalid scaling in this case can be thought of as scaling a shape in ways that you lose the inherent primitive shape. For example, scaling a SphereShape3D non-uniformly will mean it's not a perfect sphere anymore, and is thus not allowed. Similarly, rotating the local transform of a BoxShape3D and then non-uniformly scaling the body that it's contained within, will cause it to shear/skew to a point where not all angles are right angles anymore.

This has however proven to be a point of friction for some, as the error message isn't clear exactly what constitutes invalid scaling for that specific configuration of shapes, and in some cases it's not even clear why there is scaling happening, nor why it seemingly wasn't/isn't a problem when running with Godot Physics 3D (which doesn't do this type of runtime error-checking, and generally discards all scaling for things like RigidBody3D).

The delivery method of the error itself is part of the problem as well, since the spammy nature of it can be very frustrating.

This issue is meant to be a discussion around scenarios where these particular error messages are found to be annoying, and to maybe find some other approach to this problem.

Steps to reproduce

  1. Open the MRP.
  2. Run the main scene.
  3. Note errors about the box-shaped Area3D, due to shearing.
  4. Note errors about the sphere-shaped AnimatableBody3D, due to non-uniform scaling.
  5. Note errors about the capsule-shaped CharacterBody3D, due to rotating without orthonormalizing.

Minimal reproduction project (MRP)

jolt-scaling-errors.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions