Make sure the mesh actually exists before we try to specialize. (#18836)

Fixes #18809
Fixes #18823

Meshes despawned in `Last` can still be in visisible entities if they
were visible as of `PostUpdate`. Sanity check that the mesh actually
exists before we specialize. We still want to unconditionally assume
that the entity is in `EntitySpecializationTicks` as its absence from
that cache would likely suggest another bug.
This commit is contained in:
charlotte 2025-04-14 12:09:02 -07:00 committed by GitHub
parent a9b0b4e7f7
commit 6f3ea06060
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 23 additions and 23 deletions

View File

@ -1011,6 +1011,10 @@ pub fn specialize_material_meshes<M: Material>(
let Ok(material_asset_id) = material_instance.asset_id.try_typed::<M>() else {
continue;
};
let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity)
else {
continue;
};
let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(visible_entity)
@ -1022,10 +1026,6 @@ pub fn specialize_material_meshes<M: Material>(
if !needs_specialization {
continue;
}
let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity)
else {
continue;
};
let Some(mesh) = render_meshes.get(mesh_instance.mesh_asset_id) else {
continue;
};

View File

@ -945,6 +945,10 @@ pub fn specialize_prepass_material_meshes<M>(
let Ok(material_asset_id) = material_instance.asset_id.try_typed::<M>() else {
continue;
};
let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity)
else {
continue;
};
let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(visible_entity)
@ -956,10 +960,6 @@ pub fn specialize_prepass_material_meshes<M>(
if !needs_specialization {
continue;
}
let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity)
else {
continue;
};
let Some(material) = render_materials.get(material_asset_id) else {
continue;
};

View File

@ -1817,6 +1817,11 @@ pub fn specialize_shadows<M: Material>(
let Ok(material_asset_id) = material_instances.asset_id.try_typed::<M>() else {
continue;
};
let Some(mesh_instance) =
render_mesh_instances.render_mesh_queue_data(visible_entity)
else {
continue;
};
let entity_tick = entity_specialization_ticks.get(&visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(&visible_entity)
@ -1831,11 +1836,6 @@ pub fn specialize_shadows<M: Material>(
let Some(material) = render_materials.get(material_asset_id) else {
continue;
};
let Some(mesh_instance) =
render_mesh_instances.render_mesh_queue_data(visible_entity)
else {
continue;
};
if !mesh_instance
.flags
.contains(RenderMeshInstanceFlags::SHADOW_CASTER)

View File

@ -780,6 +780,10 @@ pub fn specialize_wireframes(
if !render_wireframe_instances.contains_key(visible_entity) {
continue;
};
let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity)
else {
continue;
};
let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(visible_entity)
@ -791,10 +795,6 @@ pub fn specialize_wireframes(
if !needs_specialization {
continue;
}
let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity)
else {
continue;
};
let Some(mesh) = render_meshes.get(mesh_instance.mesh_asset_id) else {
continue;
};

View File

@ -722,6 +722,9 @@ pub fn specialize_material2d_meshes<M: Material2d>(
let Some(material_asset_id) = render_material_instances.get(visible_entity) else {
continue;
};
let Some(mesh_instance) = render_mesh_instances.get_mut(visible_entity) else {
continue;
};
let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(visible_entity)
@ -733,9 +736,6 @@ pub fn specialize_material2d_meshes<M: Material2d>(
if !needs_specialization {
continue;
}
let Some(mesh_instance) = render_mesh_instances.get_mut(visible_entity) else {
continue;
};
let Some(material_2d) = render_materials.get(*material_asset_id) else {
continue;
};

View File

@ -771,6 +771,9 @@ pub fn specialize_wireframes(
if !render_wireframe_instances.contains_key(visible_entity) {
continue;
};
let Some(mesh_instance) = render_mesh_instances.get(visible_entity) else {
continue;
};
let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap();
let last_specialized_tick = view_specialized_material_pipeline_cache
.get(visible_entity)
@ -782,9 +785,6 @@ pub fn specialize_wireframes(
if !needs_specialization {
continue;
}
let Some(mesh_instance) = render_mesh_instances.get(visible_entity) else {
continue;
};
let Some(mesh) = render_meshes.get(mesh_instance.mesh_asset_id) else {
continue;
};