Skip to content

Document some deadlocks in the physics server code #108495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

simpkins
Copy link
Contributor

Add some comments documenting locations where PhysicsServer3D::soft_body_set_mesh() can deadlock.

godotengine/godot-proposals#12670 has a proposal for some alternate thread-safe soft body APIs. In the meantime it seems worth at least documenting some of the current pitfalls in the code.

Note that most people typically won't run into this deadlock today because they will crash in PhysicsServer3D::soft_body_update_rendering_server() first if trying to use SoftBody3D with a separate physics thread.

@simpkins simpkins requested a review from a team as a code owner July 10, 2025 20:56
@@ -136,6 +136,9 @@ void GodotSoftBody3D::set_mesh(RID p_mesh) {
return;
}

// TODO: calling RenderingServer::mesh_surface_get_arrays() from the physics thread
// is not safe and can deadlock. This method blocks on the main thread to return data,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// is not safe and can deadlock. This method blocks on the main thread to return data,
// is not safe and can deadlock. This method blocks on the main thread to return data,

@@ -128,6 +128,9 @@ bool JoltSoftBody3D::_ref_shared_data() {
if (iter_shared_data == mesh_to_shared.end()) {
RenderingServer *rendering = RenderingServer::get_singleton();

// TODO: calling RenderingServer::mesh_surface_get_arrays() from the physics thread
// is not safe and can deadlock. This method blocks on the main thread to return data,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// is not safe and can deadlock. This method blocks on the main thread to return data,
// is not safe and can deadlock. This method blocks on the main thread to return data,

@mihe
Copy link
Contributor

mihe commented Jul 11, 2025

It seems pertinent to mention physics/3d/run_on_separate_thread in the comments, since this deadlock presumably doesn't happen with the default settings.

Add some comments documenting locations where
PhysicsServer3D::soft_body_set_mesh() can deadlock.

godotengine/godot-proposals#12670 has a proposal for some alternate
thread-safe soft body APIs.  In the meantime it seems worth at least
documenting some of the current pitfalls in the code.
@simpkins simpkins force-pushed the deadlock_comments branch from a04deb8 to cb25b93 Compare July 13, 2025 20:45
@simpkins
Copy link
Contributor Author

Applied the review feedback.

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

Successfully merging this pull request may close these issues.

3 participants