Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view() is called multiple times despite setting loop_once() #918

Open
nebocco opened this issue May 4, 2023 · 0 comments
Open

view() is called multiple times despite setting loop_once() #918

nebocco opened this issue May 4, 2023 · 0 comments

Comments

@nebocco
Copy link

nebocco commented May 4, 2023

Hi, I found the titled issue when I was running my code on WSL Ubuntu:

use nannou::prelude::*;

fn main() {
    nannou::app(model).update(update).run();
}

struct Model(u32);

fn model(app: &App) -> Model {
    app.set_loop_mode(LoopMode::loop_once());
    let _window = app.new_window().view(view).build().unwrap();
    Model(0)
}

fn update(_app: &App, model: &mut Model, _update: Update) {
    model.0 += 1;
}

fn view(app: &App, model: &Model, frame: Frame) {
    println!("{}", model.0);
    let draw = app.draw();
    draw.background().color(WHITE);
    draw.ellipse().radius(100.0).color(BLUE);
    draw.to_frame(app, &frame).unwrap();
}

and the output was:

% cargo run --release
   Compiling loop_test v0.1.0 (/home/user/path/to/dir)
    Finished release [optimized] target(s) in 1.23s
     Running `/home/user/path/to/dir`
1
1
1
1
1

It shows that update() is called only once, as expected, while view() is called multiple times. In this example, view() is very simple, so there is no problem with its behavior. However, if you are placing particles in a full memory, the second call to view() may cause memory depletion. Is this intended behavior?

Environment:

  • OS: Win 10 Home 22H2, 19045.2913
  • WSL: 1.2.5.0
  • WSLg: 1.0.51
  • Ubuntu on WSL: 22.04.2 LTS
  • rust: 1.69.0
  • nannou: 0.18.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant