Skip to content
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

Window freezes when using PhysicsServer in background thread #37850

Closed
Tracked by #45333
gitcatrat opened this issue Apr 13, 2020 · 3 comments
Closed
Tracked by #45333

Window freezes when using PhysicsServer in background thread #37850

gitcatrat opened this issue Apr 13, 2020 · 3 comments

Comments

@gitcatrat
Copy link

Godot version:
3.2.1 Mono

OS/device including version:
macOS 10.15.4

Issue description:
When I try to use PhysicsServer in different thread, game window eventually freezes and the only way to close it is with kill -9 -PID from terminal. I get no errors, no logs, only pointless mono dump.

It seems like it's related to the load, if I add items slowly (visuals with VisualServer and static bodies + shapes with PhysicsServer), crash happens later. If I add items fast, it happens much sooner.

Physics code is very basic:

RID body = PhysicsServer.BodyCreate();
PhysicsServer.BodySetMode(body, PhysicsServer.BodyMode.Static);
RID shape = PhysicsServer.ShapeCreate(PhysicsServer.ShapeType.Box);
PhysicsServer.ShapeSetData(shape, new Vector3(cube.Size.x / 2f, cube.Size.y / 2f, cube.Size.z / 2f));
PhysicsServer.BodyAddShape(body, shape, new Transform(Basis.Identity, new Vector3(0f, cube.Size.y / 2f, 0f)));
PhysicsServer.BodySetSpace(body, Space);
PhysicsServer.BodySetState(body, PhysicsServer.BodyState.Transform, cube.Position);

// and later
PhysicsServer.FreeRid(cube.Shape);
PhysicsServer.FreeRid(cube.Body);

Steps to reproduce:
Kind of hard to describe it here, I added reproduction project. But basic steps are the following:

  • Add a method that adds an item with VisualServer and PhysicsServer
  • Constantly run that method in a background thread

Minimal reproduction project:
Issue.zip
PS! Physics code is commented out to show that VisualServer works perfectly. These few lines can be found in Cubes.cs Add and Remove methods. Remove the comments to witness the crash.

@gitcatrat
Copy link
Author

gitcatrat commented Apr 13, 2020

I want to add that:

  • rendering/threads/thread_model is Multi-Threaded
  • also occurs on exported project
  • happens with both Godot and Bullet physics

@gitcatrat
Copy link
Author

Maybe this helps?

Crashed Thread:        14  tid_d103

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Illegal instruction: 4
Termination Reason:    Namespace SIGNAL, Code 0x4
Terminating Process:   exc handler [10580]

Thread 14 Crashed:: tid_d103
0   org.godotengine.godot         	0x000000010b690dcd BroadPhaseOctree::set_static(unsigned int, bool) + 157
1   org.godotengine.godot         	0x000000010b6979c6 CollisionObjectSW::_update_shapes() + 822
2   org.godotengine.godot         	0x000000010b68a54b BodySW::set_space(SpaceSW*) + 107
3   org.godotengine.godot         	0x0000000109950b1f godot_icall_2_633(MethodBind*, Object*, RID*, RID*) + 47
4   ???                           	0x000000013aaa8852 0 + 5279221842
5   ???                           	0x00007fc052c72b40 0 + 140463999232832

@gitcatrat
Copy link
Author

Closing this as I'm not able to replicate it anymore on 4.0.rc.mono. Not sure what or which version fixed it.

Ran the minimal reproduction project (with few minor modifications) until 10,000 instances were added with static bodies.

In said project there's a 90% chance on every frame that cube + static body is added and 50% chance on every frame or when cube count is over set amount (10,000 in my case) that random cube is deleted. So it's quite volatile environment.

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

No branches or pull requests

2 participants