Skip to content

Commit b9f1179

Browse files
tychedeliamockersf
authored andcommitted
Swap order of eviction/extraction when extracting for specialization (#18846)
# Objective Fixes #18843 ## Solution We need to account for the material being added and removed in the course of the same frame. We evict the caches first because the entity will be re-added if it was marked as needing specialization, which avoids another check on removed components to see if it was "really" despawned.
1 parent 6a06e0a commit b9f1179

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

crates/bevy_pbr/src/material.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,9 @@ pub fn extract_entities_needs_specialization<M>(
822822
) where
823823
M: Material,
824824
{
825-
for entity in entities_needing_specialization.iter() {
826-
// Update the entity's specialization tick with this run's tick
827-
entity_specialization_ticks.insert((*entity).into(), ticks.this_run());
828-
}
829-
// Clean up any despawned entities
825+
// Clean up any despawned entities, we do this first in case the removed material was re-added
826+
// the same frame, thus will appear both in the removed components list and have been added to
827+
// the `EntitiesNeedingSpecialization` collection by triggering the `Changed` filter
830828
for entity in removed_mesh_material_components.read() {
831829
entity_specialization_ticks.remove(&MainEntity::from(entity));
832830
for view in views {
@@ -849,6 +847,11 @@ pub fn extract_entities_needs_specialization<M>(
849847
}
850848
}
851849
}
850+
851+
for entity in entities_needing_specialization.iter() {
852+
// Update the entity's specialization tick with this run's tick
853+
entity_specialization_ticks.insert((*entity).into(), ticks.this_run());
854+
}
852855
}
853856

854857
#[derive(Resource, Deref, DerefMut, Clone, Debug)]

crates/bevy_sprite/src/mesh2d/material.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,9 @@ pub fn extract_entities_needs_specialization<M>(
564564
) where
565565
M: Material2d,
566566
{
567-
for entity in entities_needing_specialization.iter() {
568-
// Update the entity's specialization tick with this run's tick
569-
entity_specialization_ticks.insert((*entity).into(), ticks.this_run());
570-
}
571-
// Clean up any despawned entities
567+
// Clean up any despawned entities, we do this first in case the removed material was re-added
568+
// the same frame, thus will appear both in the removed components list and have been added to
569+
// the `EntitiesNeedingSpecialization` collection by triggering the `Changed` filter
572570
for entity in removed_mesh_material_components.read() {
573571
entity_specialization_ticks.remove(&MainEntity::from(entity));
574572
for view in views {
@@ -577,6 +575,10 @@ pub fn extract_entities_needs_specialization<M>(
577575
}
578576
}
579577
}
578+
for entity in entities_needing_specialization.iter() {
579+
// Update the entity's specialization tick with this run's tick
580+
entity_specialization_ticks.insert((*entity).into(), ticks.this_run());
581+
}
580582
}
581583

582584
#[derive(Clone, Resource, Deref, DerefMut, Debug)]

0 commit comments

Comments
 (0)