From 70860aafd8acbb4af34941f1343a7ea5901a6c4e Mon Sep 17 00:00:00 2001 From: Radiant <69520693+RadiantUwU@users.noreply.github.com> Date: Sat, 31 Aug 2024 22:31:43 +0300 Subject: [PATCH] Fix shadow mesh recursion. --- drivers/gles3/storage/mesh_storage.cpp | 1 + scene/resources/mesh.cpp | 1 + servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/drivers/gles3/storage/mesh_storage.cpp b/drivers/gles3/storage/mesh_storage.cpp index d8a5b960b80..e79a62fb092 100644 --- a/drivers/gles3/storage/mesh_storage.cpp +++ b/drivers/gles3/storage/mesh_storage.cpp @@ -743,6 +743,7 @@ String MeshStorage::mesh_get_path(RID p_mesh) const { } void MeshStorage::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) { + ERR_FAIL_COND_MSG(p_mesh == p_shadow_mesh, "Cannot set a mesh as its own shadow mesh."); Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh); diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 8b5e438aea6..22e2e9138f2 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -2251,6 +2251,7 @@ Error ArrayMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, flo } void ArrayMesh::set_shadow_mesh(const Ref &p_mesh) { + ERR_FAIL_COND_MSG(p_mesh == this, "Cannot set a mesh as its own shadow mesh."); shadow_mesh = p_mesh; if (shadow_mesh.is_valid()) { RS::get_singleton()->mesh_set_shadow_mesh(mesh, shadow_mesh->get_rid()); diff --git a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp index 99622996d45..e214a9d602c 100644 --- a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp @@ -783,6 +783,7 @@ String MeshStorage::mesh_get_path(RID p_mesh) const { } void MeshStorage::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) { + ERR_FAIL_COND_MSG(p_mesh == p_shadow_mesh, "Cannot set a mesh as its own shadow mesh."); Mesh *mesh = mesh_owner.get_or_null(p_mesh); ERR_FAIL_NULL(mesh);