-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
Creating physics shapes is extremely slow #54
Comments
Should be fixed by d4ed637 |
This is great, good work! Definitely feels snappier. However, it's crashing. Blocky VT/heightmap is good. Blocky VT/custom stream is good. Everytime I try to run smooth VoxelTerrain/heightmap (your demo or mine):
VLT/noise almost always works fine. During the first session, it crashed after only the second or third creation. On my second session, I regenerated terrain probably 50 times and it didn't crash. On a third session with many terrain generations and hundreds of balls and collisions. It slowed my framerate, but wouldn't crash again.
|
Adding a surface_arrays check to VoxelBlock:set_mesh (66) like this: prevents it from crashing, however, now the terrain won't load on either your demo or mine. |
Yeah sorry I think I omitted smooth surfaces in the |
You can try with 7a7f5f6 |
Smooth terrain looks good now, thank you. Yeah I was just going to dismiss the physics crash, but it just happened again. And pushing it hard I was able to repeat it once more. It likely existed before, and is probably an engine bug. But I can't do it on command yet. Also, while abusing the system, I was able to get a different type of crash from deleting and recreating the terrain while it was still loading. Though I've done this hundreds of times without issue, this one instance crashed:
Overall, I won't worry about it unless you see something obvious or until I can reproduce on command. |
Looks like I was right to put a bound check here, otherwise the STL didn't do it at all and could end up in heap corruption (which would make it even harder to identify). If you get more crashes like this, can you please open a new issue? Like I did with #52, just listing stack traces to progressively narrow down the origin. |
Ok |
I think I found the cause of the crash db398a9 |
To put things in context, this module relies on creating a lot of unique meshes at runtime (in the hundreds). Most of it is done inside threads, but a small part is done on the main thread at a limited pace to prevent game freezing. Unfortunately, with physics turned on, Godot-related overhead is murdering that phase's performance, making the game really slow to react to dynamically loading and changing terrain (would still happen if it was done in a thread though because it's just too slow).
Creating a collision mesh is 20 times slower than creating the visual mesh. Optimizing this is important even for single edits, as they aren't as snappy as they can be.
This graph says it all, for a SINGLE 32x32x32 voxel block:
Debug build
Release_Tools build:
Debug takes 80 ms, release takes 8 ms, but overall the relative timings remain the same. There is room to at least double the speed of this.
Copying from #48:
Creating the physics mesh is litterally asking VisualServer for the vertices, which further destroys framerate not only because it triggers again the wait for the render thread, but also because it might pull the data back from the graphics card. I hope I'm wrong about the latter...
Those vertices are generated for unique voxel meshes so the cache in Mesh is also useless. But more importantly, since they are in RAM already (since I generate them), there is no point using VisualServer for anything physics-related.
Also Godot builds a BVH when TriangleMesh is created, which is completely useless when Bullet is used anyways. It basically takes almost HALF the time doing this.
One way to get around the wasted BVH would be to use
set_faces()
ourselves rather than usingcreate_trimesh_shape()
.The text was updated successfully, but these errors were encountered: