Skip to content

Commit cff1736

Browse files
authored
Deterministic fallible_systems example (#17813)
# Objective - `fallible_systems` example is not deterministic ## Solution - Make it deterministic - Also fix required feature declaration
1 parent 7398d33 commit cff1736

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,13 +2156,13 @@ wasm = false
21562156
name = "fallible_systems"
21572157
path = "examples/ecs/fallible_systems.rs"
21582158
doc-scrape-examples = true
2159+
required-features = ["bevy_mesh_picking_backend"]
21592160

21602161
[package.metadata.example.fallible_systems]
21612162
name = "Fallible Systems"
21622163
description = "Systems that return results to handle errors"
21632164
category = "ECS (Entity Component System)"
21642165
wasm = false
2165-
required-features = ["bevy_mesh_picking_backend"]
21662166

21672167
[[example]]
21682168
name = "startup_system"
@@ -4000,7 +4000,6 @@ name = "Sprite Picking"
40004000
description = "Demonstrates picking sprites and sprite atlases"
40014001
category = "Picking"
40024002
wasm = true
4003-
required-features = ["bevy_sprite_picking_backend"]
40044003

40054004
[[example]]
40064005
name = "debug_picking"

examples/ecs/fallible_systems.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use bevy::math::sampling::UniformMeshSampler;
66
use bevy::prelude::*;
77

88
use rand::distributions::Distribution;
9+
use rand::SeedableRng;
10+
use rand_chacha::ChaCha8Rng;
911

1012
fn main() {
1113
let mut app = App::new();
@@ -68,7 +70,7 @@ fn setup(
6870
mut meshes: ResMut<Assets<Mesh>>,
6971
mut materials: ResMut<Assets<StandardMaterial>>,
7072
) -> Result {
71-
let mut rng = rand::thread_rng();
73+
let mut seeded_rng = ChaCha8Rng::seed_from_u64(19878367467712);
7274

7375
// Make a plane for establishing space.
7476
commands.spawn((
@@ -116,7 +118,7 @@ fn setup(
116118
});
117119

118120
// Add sample points as children of the sphere:
119-
for point in distribution.sample_iter(&mut rng).take(10000) {
121+
for point in distribution.sample_iter(&mut seeded_rng).take(10000) {
120122
sphere.with_child((
121123
Mesh3d(point_mesh.clone()),
122124
MeshMaterial3d(point_material.clone()),

0 commit comments

Comments
 (0)