More null mesh checks (+1 squashed commits)

Squashed commits:

[c185cd4] Check for invalid mesh before using
This commit is contained in:
aidandavey 2025-11-05 22:07:53 +00:00
parent c6b22fd596
commit 6f64fc014c
2 changed files with 14 additions and 1 deletions

View File

@ -251,7 +251,12 @@ void Terrain3DInstancer::_update_mmi_by_region(const Terrain3DRegion *p_region,
}
} else {
// Needed to update generated mesh changes
RS->multimesh_set_mesh(mm, ma->get_mesh(lod)->get_rid());
Ref<Mesh> mesh = ma->get_mesh(lod);
if (!mesh.is_valid()) {
LOG(ERROR, "Mesh is null for LOD ", lod);
continue;
}
RS->multimesh_set_mesh(mm, mesh->get_rid());
}
// Capture source MM from shadow impostor LOD
if (lod == ma->get_shadow_impostor()) {

View File

@ -266,6 +266,10 @@ void Terrain3DMeshAsset::set_scene_file(const Ref<PackedScene> &p_scene_file) {
}
// Duplicate the mesh to make each Terrain3DMeshAsset unique
Ref<Mesh> mesh = mi->get_mesh()->duplicate();
if (mesh.is_null()) {
LOG(WARN, "MeshInstance3D ", mi->get_name(), " has no mesh, skipping");
continue;
}
// Apply the active material from the scene to the mesh, including MI or Geom overrides
for (int j = 0; j < mi->get_surface_override_material_count(); j++) {
Ref<Material> mat = mi->get_active_material(j);
@ -277,6 +281,10 @@ void Terrain3DMeshAsset::set_scene_file(const Ref<PackedScene> &p_scene_file) {
}
if (_meshes.size() > 0) {
Ref<Mesh> mesh = _meshes[0];
if (mesh.is_null()) {
LOG(ERROR, "First mesh is null after loading scene");
return;
}
_density = CLAMP(10.f / mesh->get_aabb().get_volume(), 0.01f, 10.0f);
} else {
set_generated_type(TYPE_TEXTURE_CARD);