From a006bd87a6f3335fae82a6146db6f11df98c9a39 Mon Sep 17 00:00:00 2001 From: Lapin Raving Date: Wed, 23 Aug 2023 15:48:05 +0200 Subject: [PATCH] fix: empty frame in redis It's caused an infinit loop. Now some point in (0, 0) with no light ar added instead of added empty frame. --- src/main.rs | 1 + src/transformer/replicate.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6ebe17d..45822b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,6 +153,7 @@ fn get_next_frame( line = transformer.apply(&line, world_state); } + info!("Draw Black -> {}", world_state.draw_black); info!("Draw Grid -> {}", world_state.draw_grid); diff --git a/src/transformer/replicate.rs b/src/transformer/replicate.rs index 590b82f..d063b49 100644 --- a/src/transformer/replicate.rs +++ b/src/transformer/replicate.rs @@ -1,4 +1,4 @@ -use crate::point::Point; +use crate::point::{Point, Color}; use crate::transformer::Transformers; use crate::worldstate::WorldState; @@ -16,10 +16,15 @@ pub enum Replicate { impl Transformers for Replicate { fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec { let mut point_list2 = vec![]; + match self { Replicate::Until(n) => { while point_list2.len() < *n { - point_list2.append(&mut point_list.to_vec()); + if point_list.len() == 0 { // to prevent infinit loop in case of empty frame + point_list2.append(&mut vec![Point{x:0., y:0., color: Color{r:0, g:0, b:0}}; *n].to_vec()); + } else { + point_list2.append(&mut point_list.to_vec()); + } } } Replicate::Times(n) => {