Skip to content

Commit

Permalink
Fix bug with changing # of particles after using inflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Masterchef365 committed Nov 16, 2023
1 parent 4c0a3b5 commit 8705790
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub struct TemplateApp {

width: usize,
height: usize,
n_particles: usize,
calc_rest_density_from_radius: bool,
show_arrows: bool,
show_grid: bool,
Expand Down Expand Up @@ -74,7 +73,6 @@ impl TemplateApp {
sim,
width,
height,
n_particles,
solver: IncompressibilitySolver::GaussSeidel,
well: false,
source_color_idx: 0,
Expand Down Expand Up @@ -190,17 +188,18 @@ impl TemplateApp {
ui.separator();
ui.strong("Simulation state");

let mut n_particles = self.sim.particles.len();
if ui
.add(
DragValue::new(&mut self.n_particles)
DragValue::new(&mut n_particles)
.prefix("# of particles: ")
.clamp_range(1..=usize::MAX)
.speed(4),
)
.changed()
{
let mut rng = rand::thread_rng();
self.sim.particles.resize_with(self.n_particles, || {
self.sim.particles.resize_with(n_particles, || {
random_particle(
&mut rng,
self.sim.grid.width(),
Expand Down Expand Up @@ -448,7 +447,7 @@ impl TemplateApp {
self.sim = Sim::new(
self.width,
self.height,
self.n_particles,
self.sim.particles.len(),
self.sim.particle_radius,
self.sim.life.clone(),
);
Expand Down

0 comments on commit 8705790

Please sign in to comment.