Shorten some lifetimes to prevent borrowing errors. Close
@@ -69,6 +69,7 @@ fn main() -> Result<(), Box<dyn Error>> {
H,
WindowOptions::default(),
)?;
+ let cs = {
let root =
BitMapBackend::<BGRXPixel>::with_buffer_and_format(buf.borrow_mut(), (W as u32, H as u32))?
.into_drawing_area();
@@ -87,6 +88,8 @@ fn main() -> Result<(), Box<dyn Error>> {
let cs = chart.into_chart_state();
root.present()?;
+ cs
+ };
let mut data = VecDeque::new();
let start_ts = SystemTime::now();
@@ -117,11 +120,13 @@ fn main() -> Result<(), Box<dyn Error>> {
data.push_back((epoch, phase_x.sin(), phase_y.sin()));
if epoch - last_flushed > 1.0 / FREAME_RATE {
+ {
let root = BitMapBackend::<BGRXPixel>::with_buffer_and_format(
buf.borrow_mut(),
(W as u32, H as u32),
)?
.into_drawing_area();
+ {
let mut chart = cs.clone().restore(&root);
chart.plotting_area().fill(&BLACK)?;
@@ -139,9 +144,8 @@ fn main() -> Result<(), Box<dyn Error>> {
)
},
))?;
-
+ }
root.present()?;
- drop(chart);
if let Some(keys) = window.get_keys_pressed(KeyRepeat::Yes) {
for key in keys {
@@ -166,9 +170,8 @@ fn main() -> Result<(), Box<dyn Error>> {
}
xphase += 2.0 * epoch * std::f64::consts::PI * (old_fx - fx);
yphase += 2.0 * epoch * std::f64::consts::PI * (old_fy - fy);
-
+ }
window.set_title(&get_window_title(fx, fy, yphase - xphase));
- break;
}
}
