godotengine / godot

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

MultiMesh3D throws errors and can corrupt scenes, Condition "instance_count > 0" is true. #87166

Open viksl opened 8 months ago

viksl commented 8 months ago

Tested versions

4.2.1 bot standard and mono

System information

Windows 11 - Vulkan - Nvidia RTX 4070 - intel i5 13600KF

Issue description

For some reason MultiMesh3D now throws an error like this:

image (screenshot is from mono version but same error happens in the standard godot version)

and it can also lead to scene corruption - I don't know the conditions for that, sometimes my scenes just get corrupted when I add the multimesh, I have no idea why, it's not any particular mesh itself I tried built-in ones too.

Steps to reproduce

With MRP: Open the project if you don't see the error on the first try (no .godot folder yet so it doesn't show) then close the project and open it again, you should see it now or after opening the scene with the MultiMesh3D (called planet.tscn) - you might need to have both scenes open when you close the project so they reopen. (sometimes under no idea what circumstances you can get a corrupted scene error and the scene will no longer open though I have no idea why or how to reproduce this)

Without MRP:

  1. Make a scene with MultiMesh3D and populate a surface with some MeshInstance3D (for testing I used the Cylinder mesh) and save it as a scene.
  2. Instantiate that scene into your main scene.
  3. Run your project.
  4. Close the project and open it again
  5. You should see the error now or after opening the scene with the MultiMesh3D.

Minimal reproduction project (MRP)

MultiMeshMRP.zip

viksl commented 8 months ago

Just got this error which after closing and reopening the project results in scene corruption.

ERROR: Condition "!sdata.is_valid()" is true. Returning: nullptr
   at: instantiate (scene/resources/packed_scene.cpp:220)
ERROR: Failed to load scene dependency: "res://Scenes/CelestialBodies/Asteroid/Asteroid.tscn". Make sure the required s.   at: (scene/resources/packed_scene.cpp:222)
ERROR: Failed loading scene: res://Scenes/Playground/Playground.tscn.
   at: (main/main.cpp:3431)
ERROR: 7 RID allocations of type 'P11GodotBody3D' were leaked at exit.
ERROR: 4 RID allocations of type 'P12GodotShape3D' were leaked at exit.
ERROR: Pages in use exist at exit in PagedAllocator: N33RendererSceneRenderImplementation22RenderForwardClustered32GeomE   at: ~PagedAllocator (./core/templates/paged_allocator.h:170)
ERROR: 1 RID allocations of type 'N10RendererRD5SkyRD3SkyE' were leaked at exit.
ERROR: 1 RID allocations of type 'N26RendererEnvironmentStorage11EnvironmentE' were leaked at exit.
ERROR: 1 RID allocations of type 'N10RendererRD16ParticlesStorage9ParticlesE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
ERROR: 1 RID allocations of type 'N10RendererRD12LightStorage13LightInstanceE' were leaked at exit.
ERROR: 1 RID allocations of type 'N10RendererRD12LightStorage5LightE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
ERROR: 3 RID allocations of type 'N10RendererRD11MeshStorage9MultiMeshE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
ERROR: 12 RID allocations of type 'N10RendererRD11MeshStorage4MeshE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56Godot Engine v4.2.1.stable.mono.official.b09f793f5 - htgVulkan API 1.3.260 - Forward+ - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce RTX 4070

ERROR: Condition "!sdata.is_valid()" is true. Returning: nullptr
   at: instantiate (scene/resources/packed_scene.cpp:220)
ERROR: Failed to load scene dependency: "res://Scenes/CelestialBodies/Asteroid/Asteroid.tscn". Make sure the required s.   at: (scene/resources/packed_scene.cpp:222)
ERROR: Failed loading scene: res://Scenes/Playground/Playground.tscn.
   at: (main/main.cpp:3431)
ERROR: 7 RID allocations of type 'P11GodotBody3D' were leaked at exit.
ERROR: 4 RID allocations of type 'P12GodotShape3D' were leaked at exit.
ERROR: Pages in use exist at exit in PagedAllocator: N33RendererSceneRenderImplementation22RenderForwardClustered32GeomE   at: ~PagedAllocator (./core/templates/paged_allocator.h:170)
ERROR: 1 RID allocations of type 'N10RendererRD5SkyRD3SkyE' were leaked at exit.
ERROR: 1 RID allocations of type 'N26RendererEnvironmentStorage11EnvironmentE' were leaked at exit.
ERROR: 1 RID allocations of type 'N10RendererRD16ParticlesStorage9ParticlesE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
ERROR: 1 RID allocations of type 'N10RendererRD12LightStorage13LightInstanceE' were leaked at exit.
ERROR: 1 RID allocations of type 'N10RendererRD12LightStorage5LightE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
ERROR: 3 RID allocations of type 'N10RendererRD11MeshStorage9MultiMeshE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
ERROR: 12 RID allocations of type 'N10RendererRD11MeshStorage4MeshE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.

This error below shows in the terminal after reopening the project:

ERROR: Condition "!sdata.is_valid()" is true. Returning: nullptr
   at: instantiate (scene/resources/packed_scene.cpp:220)
ERROR: Failed to load scene dependency: "res://Scenes/CelestialBodies/Asteroid/Asteroid.tscn". Make sure the required s.
   at: (scene/resources/packed_scene.cpp:222)
ERROR: Index p_idx = 1 is out of bounds (edited_scene.size() = 1).
   at: remove_scene (editor/editor_data.cpp:626)
ERROR: Condition "instance_count > 0" is true.
   at: set_transform_format (scene/resources/multimesh.cpp:299)
ERROR: Condition "instance_count > 0" is true.
   at: set_transform_format (scene/resources/multimesh.cpp:299)
ERROR: Condition "instance_count > 0" is true.
   at: set_transform_format (scene/resources/multimesh.cpp:299)
ERROR: Condition "!sdata.is_valid()" is true. Returning: nullptr
   at: instantiate (scene/resources/packed_scene.cpp:220)
ERROR: Attempting to parent and popup a dialog that already has a parent.
   at: (scene/main/window.cpp:1773)
ERROR: Index p_idx = 1 is out of bounds (edited_scene.size() = 1).
   at: remove_scene (editor/editor_data.cpp:626)

I don't know why this happens. What I do is I add a 3D model (glb), make it an editable children so the mesh can be targeted from MeshInstance3D, target my main mesh (godot sphere) as a surface, set some random scale and lower the number of instances. That's all, I then try to play the project but the instances don't show up (they only show in the editor), my scene is instantiated couple times in my main scene so when I move to the main scene the instances show but I get the first errors above. When I close the editor and open back there's a popup with scene corruption and the terminal has the above, mentioned as second, errors.

I tried to replicate this in a fresh new scene but so far no luck, I'm not sure why, my original scene isn't particularly much different, it only has couple godot nodes. It does not happen when adding any other nodes so only with the MeshInstance3D.

The model itself is nothing special either, I put together a sphere and a cylinder in blender and exported it as a placeholder (both have a material, both joined as one mesh) but using it agian in a different scene isn't an issue, I also tried making a new model and exporting again and again exactly same issues so I assume it's not just

I'm keeping this as a comment since I'm not sure if it's relevant to what the fix here https://github.com/godotengine/godot/pull/87205 already deals with.

EDIT: Ok, as I posted this it happened with the brand new scene too but I had to go to the model (double click to open the Import window) and set mesh save paths and reimport the model (so the *.res files is created in file system). After that I added new meshinstance and so on as mentioned above and it gets corrupted.

Here's the model in question but as mentioned it happens with other models too. Tree.zip

With the same error (though for some reason the error log did not fully print as you can see at the end):

ERROR: Condition "!sdata.is_valid()" is true. Returning: nullptr
   at: instantiate (scene/resources/packed_scene.cpp:220)
ERROR: Failed to load scene dependency: "res://Scenes/Playground/TestCorruptionMainInherited.tscn". Make sure the requi.
   at: (scene/resources/packed_scene.cpp:222)
ERROR: Failed loading scene: res://Scenes/Playground/Playground.tscn.
   at: (main/main.cpp:3431)
ERROR: 32 RID allocations of type 'P11GodotBody3D' were leaked at exit.
ERROR: 4 RID allocations of type 'P12GodotShape3D' were leaked at exit.
ERROR: Pages in use exist at exit in PagedAllocator: N33RendererSceneRenderImplementation22RenderForwardClustered32GeomE
   at: ~PagedAllocator (./core/templates/paged_allocator.h:170)
ERROR: 1 RID allocations of type 'N10RendererRD5SkyRD3SkyE' were leaked at exit.
ERROR: 1 RID allocations of typ