godotengine / godot

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

Parameter "material" is null error spam when deleting objects that have 2 material overrides #85817

Open jitspoe opened 9 months ago

jitspoe commented 9 months ago

Tested versions

System information

Windows 10, Vulkan forward +

Issue description

Tons of spam in the error log about material being null: image

E 0:06:51:0938   RendererRD::MaterialStorage::material_casts_shadows: Parameter "material" is null.
  <C++ Source>   servers\rendering\renderer_rd\storage_rd\material_storage.cpp:2213 @ RendererRD::MaterialStorage::material_casts_shadows()
E 0:06:56:0296   RendererRD::MaterialStorage::material_is_animated: Parameter "material" is null.
  <C++ Source>   servers\rendering\renderer_rd\storage_rd\material_storage.cpp:2200 @ RendererRD::MaterialStorage::material_is_animated()
E 0:06:56:0296   RendererRD::MaterialStorage::material_get_instance_shader_parameters: Parameter "material" is null.
  <C++ Source>   servers\rendering\renderer_rd\storage_rd\material_storage.cpp:2226 @ RendererRD::MaterialStorage::material_get_instance_shader_parameters()
E 0:06:56:0297   RendererRD::MaterialStorage::material_update_dependency: Parameter "material" is null.
  <C++ Source>   servers\rendering\renderer_rd\storage_rd\material_storage.cpp:2238 @ RendererRD::MaterialStorage::material_update_dependency()

etc.

Steps to reproduce

  1. Create a scene
  2. Add a mesh instance to the scene (Mesh 1).
  3. Set a material (We'll call it Material A) on Mesh 1 in the Geometry, Material Override slot.
  4. Add another mesh (Mesh 2).
  5. Set Material A on Mesh 2's Material Override slot.
  6. Set a different material (Material B) on the "Surface Material Override" slot of Mesh 2.
  7. Load, instantiate, and add this scene as a child of another scene.
  8. queue_free() the scene.
  9. Note error spam.

This took ages to figure out exactly what caused this, haha.

Minimal reproduction project (MRP)

test_null_material_spam.zip

jitspoe commented 9 months ago

Note that while the simplest case to repro this seems to be easy to work around (don't have 2 material overrides on the same mesh), this can also be triggered by other combinations, like having a material on one mesh in the geometry material override and on another mesh in the mesh's surface material override, so you could have this error occur even with just 1 override. Making each use of the material use the same override seems to work around the issue.

Neuroburst commented 3 months ago

As another workaround, you can just clear the material before the node is queue_free()'d

Yilun-Sun commented 1 month ago

As another workaround, you can just clear the material before the node is queue_free()'d

Works for me!