Skip to content

Commit d6db78b

Browse files
authored
Replace internal uses of insert_or_spawn_batch (#18035)
## Objective `insert_or_spawn_batch` is due to be deprecated eventually (#15704), and removing uses internally will make that easier. ## Solution Replaced internal uses of `insert_or_spawn_batch` with `try_insert_batch` (non-panicking variant because `insert_or_spawn_batch` didn't panic). All of the internal uses are in rendering code. Since retained rendering was meant to get rid non-opaque entity IDs, I assume the code was just using `insert_or_spawn_batch` because `insert_batch` didn't exist and not because it actually wanted to spawn something. However, I am *not* confident in my ability to judge rendering code.
1 parent 06cb5c5 commit d6db78b

File tree

10 files changed

+15
-15
lines changed

10 files changed

+15
-15
lines changed

crates/bevy_pbr/src/render/light.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub fn extract_lights(
347347
));
348348
}
349349
*previous_point_lights_len = point_lights_values.len();
350-
commands.insert_or_spawn_batch(point_lights_values);
350+
commands.try_insert_batch(point_lights_values);
351351

352352
let mut spot_lights_values = Vec::with_capacity(*previous_spot_lights_len);
353353
for entity in global_point_lights.iter().copied() {
@@ -410,7 +410,7 @@ pub fn extract_lights(
410410
}
411411
}
412412
*previous_spot_lights_len = spot_lights_values.len();
413-
commands.insert_or_spawn_batch(spot_lights_values);
413+
commands.try_insert_batch(spot_lights_values);
414414

415415
for (
416416
main_entity,

crates/bevy_pbr/src/wireframe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn apply_wireframe_material(
167167
let material = get_wireframe_material(maybe_color, &mut materials, &global_material);
168168
material_to_spawn.push((e, MeshMaterial3d(material)));
169169
}
170-
commands.insert_or_spawn_batch(material_to_spawn);
170+
commands.try_insert_batch(material_to_spawn);
171171
}
172172

173173
type WireframeFilter = (With<Mesh3d>, Without<Wireframe>, Without<NoWireframe>);
@@ -195,7 +195,7 @@ fn apply_global_wireframe_material(
195195
// This makes it easy to detect which mesh is using the global material and which ones are user specified
196196
material_to_spawn.push((e, MeshMaterial3d(material)));
197197
}
198-
commands.insert_or_spawn_batch(material_to_spawn);
198+
commands.try_insert_batch(material_to_spawn);
199199
} else {
200200
for e in &meshes_with_global_material {
201201
commands

crates/bevy_render/src/extract_component.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn prepare_uniform_components<C>(
154154
)
155155
})
156156
.collect::<Vec<_>>();
157-
commands.insert_or_spawn_batch(entities);
157+
commands.try_insert_batch(entities);
158158
}
159159

160160
/// This plugin extracts the components into the render world for synced entities.
@@ -212,7 +212,7 @@ fn extract_components<C: ExtractComponent>(
212212
}
213213
}
214214
*previous_len = values.len();
215-
commands.insert_or_spawn_batch(values);
215+
commands.try_insert_batch(values);
216216
}
217217

218218
/// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are visible and synced via [`crate::sync_world::SyncToRenderWorld`].
@@ -232,5 +232,5 @@ fn extract_visible_components<C: ExtractComponent>(
232232
}
233233
}
234234
*previous_len = values.len();
235-
commands.insert_or_spawn_batch(values);
235+
commands.try_insert_batch(values);
236236
}

crates/bevy_render/src/gpu_component_array_buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn prepare_gpu_component_array_buffers<C: Component + GpuArrayBufferable>(
5353
.iter()
5454
.map(|(entity, component)| (entity, gpu_array_buffer.push(component.clone())))
5555
.collect::<Vec<_>>();
56-
commands.insert_or_spawn_batch(entities);
56+
commands.try_insert_batch(entities);
5757

5858
gpu_array_buffer.write_buffer(&render_device, &render_queue);
5959
}

crates/bevy_sprite/src/mesh2d/wireframe2d.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn apply_wireframe_material(
180180
};
181181
wireframes_to_spawn.push((e, MeshMaterial2d(material)));
182182
}
183-
commands.insert_or_spawn_batch(wireframes_to_spawn);
183+
commands.try_insert_batch(wireframes_to_spawn);
184184
}
185185

186186
type Wireframe2dFilter = (With<Mesh2d>, Without<Wireframe2d>, Without<NoWireframe2d>);
@@ -209,7 +209,7 @@ fn apply_global_wireframe_material(
209209
// This makes it easy to detect which mesh is using the global material and which ones are user specified
210210
material_to_spawn.push((e, MeshMaterial2d(global_material.handle.clone())));
211211
}
212-
commands.insert_or_spawn_batch(material_to_spawn);
212+
commands.try_insert_batch(material_to_spawn);
213213
} else {
214214
for e in &meshes_with_global_material {
215215
commands

crates/bevy_ui/src/render/box_shadow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ pub fn prepare_shadows(
526526
ui_meta.vertices.write_buffer(&render_device, &render_queue);
527527
ui_meta.indices.write_buffer(&render_device, &render_queue);
528528
*previous_len = batches.len();
529-
commands.insert_or_spawn_batch(batches);
529+
commands.try_insert_batch(batches);
530530
}
531531
extracted_shadows.box_shadows.clear();
532532
}

crates/bevy_ui/src/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ pub fn prepare_uinodes(
13891389
ui_meta.vertices.write_buffer(&render_device, &render_queue);
13901390
ui_meta.indices.write_buffer(&render_device, &render_queue);
13911391
*previous_len = batches.len();
1392-
commands.insert_or_spawn_batch(batches);
1392+
commands.try_insert_batch(batches);
13931393
}
13941394
extracted_uinodes.clear();
13951395
}

crates/bevy_ui/src/render/ui_material_pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ pub fn prepare_uimaterial_nodes<M: UiMaterial>(
578578
}
579579
ui_meta.vertices.write_buffer(&render_device, &render_queue);
580580
*previous_len = batches.len();
581-
commands.insert_or_spawn_batch(batches);
581+
commands.try_insert_batch(batches);
582582
}
583583
extracted_uinodes.uinodes.clear();
584584
}

crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ pub fn prepare_ui_slices(
649649
ui_meta.vertices.write_buffer(&render_device, &render_queue);
650650
ui_meta.indices.write_buffer(&render_device, &render_queue);
651651
*previous_len = batches.len();
652-
commands.insert_or_spawn_batch(batches);
652+
commands.try_insert_batch(batches);
653653
}
654654
extracted_slices.slices.clear();
655655
}

examples/2d/mesh2d_manual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ pub fn extract_colored_mesh2d(
357357
);
358358
}
359359
*previous_len = values.len();
360-
commands.insert_or_spawn_batch(values);
360+
commands.try_insert_batch(values);
361361
}
362362

363363
/// Queue the 2d meshes marked with [`ColoredMesh2d`] using our custom pipeline and draw function

0 commit comments

Comments
 (0)