From 179e2eb218959a225bfe95a7471a424076edbfb9 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska <67589014+mgrudzinska@users.noreply.github.com> Date: Wed, 17 Apr 2024 04:25:27 +0200 Subject: [PATCH] sw_engine: fix max length of trimmed strokes The error was visible when multiple shapes were simultaneously trimmed. The length of a single shape was zeroed out only in selected cases, which caused accumulation that could lead to incorrect extension of the variable determining the maximum length. @issue: https://github.com/thorvg/thorvg/issues/2173 --- src/renderer/sw_engine/tvgSwShape.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/renderer/sw_engine/tvgSwShape.cpp b/src/renderer/sw_engine/tvgSwShape.cpp index 70cc1bf9..e38f13db 100644 --- a/src/renderer/sw_engine/tvgSwShape.cpp +++ b/src/renderer/sw_engine/tvgSwShape.cpp @@ -370,8 +370,8 @@ static float _outlineLength(const RenderShape* rshape) const Point* close = nullptr; auto length = 0.0f; - auto slength = 0.0f; - auto simutaneous = !rshape->stroke->trim.individual; + auto slength = -1.0f; + auto simultaneous = !rshape->stroke->trim.individual; //Compute the whole length while (cmdCnt-- > 0) { @@ -379,8 +379,8 @@ static float _outlineLength(const RenderShape* rshape) case PathCommand::Close: { length += mathLength(pts - 1, close); //retrieve the max length of the shape if the simultaneous mode. - if (simutaneous && slength < length) { - slength = length; + if (simultaneous) { + if (slength < length) slength = length; length = 0.0f; } break; @@ -403,7 +403,7 @@ static float _outlineLength(const RenderShape* rshape) } ++cmds; } - if (simutaneous && slength > length) return slength; + if (simultaneous && slength > length) return slength; else return length; }