Skip to content

Commit

Permalink
Deterministic fallible_systems example (#17813)
Browse files Browse the repository at this point in the history
# Objective

- `fallible_systems` example is not deterministic

## Solution

- Make it deterministic
- Also fix required feature declaration
  • Loading branch information
mockersf authored Feb 11, 2025
1 parent 7398d33 commit cff1736
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2156,13 +2156,13 @@ wasm = false
name = "fallible_systems"
path = "examples/ecs/fallible_systems.rs"
doc-scrape-examples = true
required-features = ["bevy_mesh_picking_backend"]

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

[[example]]
name = "startup_system"
Expand Down Expand Up @@ -4000,7 +4000,6 @@ name = "Sprite Picking"
description = "Demonstrates picking sprites and sprite atlases"
category = "Picking"
wasm = true
required-features = ["bevy_sprite_picking_backend"]

[[example]]
name = "debug_picking"
Expand Down
6 changes: 4 additions & 2 deletions examples/ecs/fallible_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use bevy::math::sampling::UniformMeshSampler;
use bevy::prelude::*;

use rand::distributions::Distribution;
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;

fn main() {
let mut app = App::new();
Expand Down Expand Up @@ -68,7 +70,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) -> Result {
let mut rng = rand::thread_rng();
let mut seeded_rng = ChaCha8Rng::seed_from_u64(19878367467712);

// Make a plane for establishing space.
commands.spawn((
Expand Down Expand Up @@ -116,7 +118,7 @@ fn setup(
});

// Add sample points as children of the sphere:
for point in distribution.sample_iter(&mut rng).take(10000) {
for point in distribution.sample_iter(&mut seeded_rng).take(10000) {
sphere.with_child((
Mesh3d(point_mesh.clone()),
MeshMaterial3d(point_material.clone()),
Expand Down

0 comments on commit cff1736

Please sign in to comment.