sunjay / turtle

Create Animated Drawings in Rust
http://turtle.rs
Mozilla Public License 2.0
559 stars 54 forks source link

Window freezes instead of closing #185

Open sunjay opened 4 years ago

sunjay commented 4 years ago

This is likely related at least in part to some of the issues in #183. In #173, we made it so that you could manage multiple turtle windows in multiple threads. We did that by no longer calling process::exit when a window is closed.

Unfortunately, if you create a window in a separate thread, closing the window doesn't actually cause the window to close. The following code reproduces the issue:

use std::thread;

use turtle::Turtle;

fn main() {
    turtle::start();

    thread::spawn(|| {
        let mut turtle = Turtle::new();

        for _ in 0..360 {
            // Move forward three steps
            turtle.forward(3.0);
            // Rotate to the right (clockwise) by 1 degree
            turtle.right(1.0);
            // panic!(); //TODO: Window should close
        }
    });

    thread::park();
}

Running this code and closing the window at any point should cause the window to disappear. Instead, the window remains open and freezes in place. The commented out panic!() should also cause the window to close, but it also results in the window just freezing instead.