Skip to content

Allow access to PhysicsDirectSpaceState3D from outside the main thread. #973

Description

@DAShoe1

Tested versions

This issue is present when using a physics engine module such as GodotPhysics or the new JoltPhysics module.
This is not an issue when using Jolt physics as a GDExtension.

System information

Windows 11

Issue description

The following code prevents access to the PhysicsDirectSpaceState3D outside of the main thread,

// this function only works on physics process, errors and returns null otherwise
PhysicsDirectSpaceState3D *space_get_direct_state(RID p_space) override {
ERR_FAIL_COND_V(!Thread::is_main_thread(), nullptr);
return physics_server_3d->space_get_direct_state(p_space);
}

I don't believe this check is necessary as there is another check later that verifies that the space state is available,

PhysicsDirectSpaceState3D *JoltPhysicsServer3D::space_get_direct_state(RID p_space) {
JoltSpace3D *space = space_owner.get_or_null(p_space);
ERR_FAIL_NULL_V(space, nullptr);
ERR_FAIL_COND_V_MSG((on_separate_thread && !doing_sync) || space->is_stepping(), nullptr, "Space state is inaccessible right now, wait for iteration or physics process notification.");
return space->get_direct_state();
}

Removing the main thread check in a custom build allows my project to work with the integrated Jolt physics module just as it does with the GDExtension version.

Steps to reproduce

Attempt a raycast from a thread or from a node running on a sub thread group.

Minimal reproduction project (MRP)

N/A

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions