godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.55k stars 21.08k forks source link

Crash in visual server with SoftBody simulation #51652

Closed pouleyKetchoupp closed 3 years ago

pouleyKetchoupp commented 3 years ago

Godot version

3.4.dev (263a5328b8d56ccdc1cd8d0baf30719e5b8e5023)

System information

Windows 10

Issue description

On the 3.x branch (but after 3.4 beta 3 so not in public release yet) any soft body simulation causes errors and a crash in render.

Git bisect shows this is caused by #51376 (CC @The-O-king).

Errors:

ERROR: Condition "array.size() != array_size" is true.
   at: RasterizerStorageGLES3::mesh_add_surface (drivers\gles3\rasterizer_storage_gles3.cpp:3579)
ERROR: Index p_surface = 0 is out of bounds (instance->materials.size() = 0).
   at: VisualServerScene::instance_set_surface_material (servers\visual\visual_server_scene.cpp:729)
ERROR: Index p_surface = 0 is out of bounds (mesh->surfaces.size() = 0).
   at: RasterizerStorageGLES3::mesh_surface_get_array (drivers\gles3\rasterizer_storage_gles3.cpp:3914)
ERROR: Condition "vertex_data.size() == 0" is true. Returned: Array()
   at: VisualServer::mesh_surface_get_arrays (servers\visual_server.cpp:1707)
ERROR: Index p_surface = 0 is out of bounds (mesh->surfaces.size() = 0).
   at: RasterizerStorageGLES3::mesh_surface_get_format (drivers\gles3\rasterizer_storage_gles3.cpp:3979)
ERROR: Condition "!(soft_mesh->surface_get_format(0) & VisualServer::ARRAY_FORMAT_INDEX)" is true.
   at: SoftBodyBullet::set_soft_mesh (modules\bullet\soft_body_bullet.cpp:132)
ERROR: Index p_surface = 0 is out of bounds (mesh->surfaces.size() = 0).
   at: RasterizerStorageGLES3::mesh_surface_get_array (drivers\gles3\rasterizer_storage_gles3.cpp:3914)
ERROR: Condition "vertex_data.size() == 0" is true. Returned: Array()
   at: VisualServer::mesh_surface_get_arrays (servers\visual_server.cpp:1707)
ERROR: FATAL: Index p_index = 0 is out of bounds (((Vector<T> *)(this))->_cowdata.size() = 0).
   at: VectorWriteProxy<class Variant>::operator [] (C:\dev\godot-3.2\core/vector.h:49)

Crash callstack (forced crash on accessing bad index in Vector):

godot.windows.tools.64.exe!VectorWriteProxy<Variant>::operator[](int p_index) Line 49   C++
godot.windows.tools.64.exe!Array::operator[](int p_idx) Line 75 C++
godot.windows.tools.64.exe!SoftBodyBullet::reset_all_node_positions() Line 236  C++
godot.windows.tools.64.exe!SoftBodyBullet::set_soft_transform(const Transform & p_transform) Line 152   C++
godot.windows.tools.64.exe!BulletPhysicsServer::soft_body_set_transform(RID p_body, const Transform & p_transform) Line 1005    C++
godot.windows.tools.64.exe!SoftBody::_notification(int p_what) Line 285 C++
godot.windows.tools.64.exe!SoftBody::_notificationv(int p_notification, bool p_reversed) Line 66    C++
godot.windows.tools.64.exe!Object::notification(int p_notification, bool p_reversed) Line 929   C++
godot.windows.tools.64.exe!SceneTree::flush_transform_notifications() Line 159  C++
godot.windows.tools.64.exe!SceneTree::iteration(float p_time) Line 475  C++
godot.windows.tools.64.exe!Main::iteration() Line 2135  C++

Steps to reproduce

It seems to happen with any soft body simulation. Just run the attached MRP and observe the errors and crash.

Minimal reproduction project

soft-body-simple-test-3.x.zip

The-O-King commented 3 years ago

Commenting to let you know I'm looking into it!

pouleyKetchoupp commented 3 years ago

Fixed by #51769.