This commit is contained in:
1 parent
d1a56f77cc
commit
0e7aed40f1
21 files changed
+1253
-19
No files matched your search
@@ -311,13 +311,24 @@ fn sync_terrain_layer_material_bindings(
|
||||
);
|
||||
handle
|
||||
});
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<MeshMaterial3d<StandardMaterial>>()
|
||||
.insert(MeshMaterial3d(handle));
|
||||
queue_terrain_material_binding(&mut commands, entity, handle);
|
||||
}
|
||||
}
|
||||
|
||||
fn queue_terrain_material_binding(
|
||||
commands: &mut Commands,
|
||||
entity: Entity,
|
||||
handle: Handle<TerrainLayerMaterial>,
|
||||
) {
|
||||
// Generated render entities can be removed by a scene switch after this system's query
|
||||
// but before deferred commands apply. That lifecycle race is expected and must not abort
|
||||
// the editor while opening another scene.
|
||||
commands
|
||||
.entity(entity)
|
||||
.try_remove::<MeshMaterial3d<StandardMaterial>>()
|
||||
.try_insert(MeshMaterial3d(handle));
|
||||
}
|
||||
|
||||
fn terrain_layer_revision(layers: &[TerrainMaterialLayer]) -> u64 {
|
||||
let mut dependencies = layers
|
||||
.iter()
|
||||
@@ -469,8 +480,8 @@ fn sync_surface_material_bindings(
|
||||
{
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<MeshMaterial3d<SurfaceMaterial>>()
|
||||
.insert(MeshMaterial3d(handle));
|
||||
.try_remove::<MeshMaterial3d<SurfaceMaterial>>()
|
||||
.try_insert(MeshMaterial3d(handle));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -540,8 +551,8 @@ fn sync_surface_material_bindings(
|
||||
{
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<MeshMaterial3d<SurfaceMaterial>>()
|
||||
.insert(MeshMaterial3d(handle));
|
||||
.try_remove::<MeshMaterial3d<SurfaceMaterial>>()
|
||||
.try_insert(MeshMaterial3d(handle));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -565,8 +576,8 @@ fn sync_surface_material_bindings(
|
||||
if surface_handle.is_none_or(|current| current.0 != handle) {
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<MeshMaterial3d<StandardMaterial>>()
|
||||
.insert(MeshMaterial3d(handle));
|
||||
.try_remove::<MeshMaterial3d<StandardMaterial>>()
|
||||
.try_insert(MeshMaterial3d(handle));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -957,6 +968,21 @@ pub fn compose_surface_shader(evaluator: &str) -> String {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bevy::ecs::world::CommandQueue;
|
||||
|
||||
#[test]
|
||||
fn stale_generated_terrain_binding_is_nonfatal_during_scene_switch() {
|
||||
let mut world = World::new();
|
||||
let entity = world.spawn_empty().id();
|
||||
let mut queue = CommandQueue::default();
|
||||
let mut commands = Commands::new(&mut queue, &world);
|
||||
queue_terrain_material_binding(&mut commands, entity, Handle::default());
|
||||
|
||||
world.entity_mut(entity).despawn();
|
||||
queue.apply(&mut world);
|
||||
|
||||
assert!(world.get_entity(entity).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_resource_bindings_and_missing_entry() {
|
||||
|
||||
Reference in new issue
Block a user