diff --git a/render/common_tess/src/lib.rs b/render/common_tess/src/lib.rs index be09a3217..76909882e 100644 --- a/render/common_tess/src/lib.rs +++ b/render/common_tess/src/lib.rs @@ -396,10 +396,21 @@ fn ruffle_path_to_lyon_path(commands: Vec, is_closed: bool) -> Path } let mut builder = Path::builder(); - for cmd in commands { + let mut cmds = commands.into_iter().peekable(); + while let Some(cmd) = cmds.next() { match cmd { DrawCommand::MoveTo { x, y } => { - builder.move_to(point(x, y)); + // Lyon (incorrectly?) will make a 0-length line segment if you have consecutive MoveTos. + // Filter out consecutive MoveTos, only committing the last one. + let mut cursor_pos = (x, y); + while let Some(DrawCommand::MoveTo { x, y }) = cmds.peek() { + cursor_pos = (*x, *y); + cmds.next(); + } + + if cmds.peek().is_some() { + builder.move_to(point(cursor_pos.0, cursor_pos.1)); + } } DrawCommand::LineTo { x, y } => { builder.line_to(point(x, y)); diff --git a/render/wgpu/src/utils.rs b/render/wgpu/src/utils.rs index 6e07d4a67..053b70027 100644 --- a/render/wgpu/src/utils.rs +++ b/render/wgpu/src/utils.rs @@ -33,10 +33,21 @@ pub fn point(x: Twips, y: Twips) -> lyon::math::Point { pub fn ruffle_path_to_lyon_path(commands: Vec, is_closed: bool) -> Path { let mut builder = Path::builder(); - for cmd in commands { + let mut cmds = commands.into_iter().peekable(); + while let Some(cmd) = cmds.next() { match cmd { DrawCommand::MoveTo { x, y } => { - builder.move_to(point(x, y)); + // Lyon (incorrectly?) will make a 0-length line segment if you have consecutive MoveTos. + // Filter out consecutive MoveTos, only committing the last one. + let mut cursor_pos = (x, y); + while let Some(DrawCommand::MoveTo { x, y }) = cmds.peek() { + cursor_pos = (*x, *y); + cmds.next(); + } + + if cmds.peek().is_some() { + builder.move_to(point(cursor_pos.0, cursor_pos.1)); + } } DrawCommand::LineTo { x, y } => { builder.line_to(point(x, y));