Skip to content

PhysicsDirectSpaceState3D::RayResult is not correctly bound #80444

Closed
@mihe

Description

Godot version

4.2.dev [f7bc653]

System information

Windows 11 (10.0.22621)

Issue description

#71233 introduced a new field to RayResult called face_index, as seen here:

struct RayResult {
Vector3 position;
Vector3 normal;
int face_index = -1;
RID rid;
ObjectID collider_id;
Object *collider = nullptr;
int shape = 0;
};

... but unfortunately the binding for RayResult (aliased as PhysicsServer3DExtensionRayResult) wasn't updated, as seen here:

GDREGISTER_NATIVE_STRUCT(PhysicsServer3DExtensionRayResult, "Vector3 position;Vector3 normal;RID rid;ObjectID collider_id;Object *collider;int shape");

... which leads to extension_api.json being emitted with a different struct layout for PhysicsServer3DExtensionRayResult compared to Godot's RayResult.

Since PhysicsDirectSpaceState3DExtension::_intersect_ray directly manipulates a pointer to a RayResult, you end up corrupting it when writing to anything past the normal field from a GDExtension, due to mismatching binary layouts.

Steps to reproduce

  • Download the MRP
  • Run the project's main scene with Godot 4.1.1
  • Note how the output mentions a non-null collider
  • Run the project's main scene with Godot 4.2 (after a56e960)
  • Note how the output mentions a null collider, as well as other errors (due to the instance ID being corrupted)

Minimal reproduction project

RayResult_MRP.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions