From 99e5388a46d5d073736f4ba703e5d6205bb94a53 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 6 May 2024 11:23:14 +0200 Subject: [PATCH] fix crash when copy rule points to outside the rule bounds after a resize --- petri/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/petri/src/lib.rs b/petri/src/lib.rs index a46a6a5..2790799 100644 --- a/petri/src/lib.rs +++ b/petri/src/lib.rs @@ -418,7 +418,12 @@ impl Dish { } } RuleCellTo::Copy(x, y) => { - let cell = old_state[x + y * variant.width]; + let index = x + y * variant.width; + if index >= old_state.len() { + // the copy source is outside the rule bounds + continue; + } + let cell = old_state[index]; if let Some(cell) = cell { // if the copy source is outside the world, do nothing self.set_cell(px, py, cell);