wg_engine: fix stroke trimming

Prevent crash for begin == end;
This commit is contained in:
Mira Grudzinska 2024-09-25 15:51:04 +02:00 committed by Hermet Park
parent ee6a7214d4
commit fa17fcde81

View file

@ -362,26 +362,24 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
appendShape(context, path_buff); appendShape(context, path_buff);
}); });
// append shape with strokes // append shape with strokes
} else if (rshape.stroke->trim.simultaneous) { } else {
float tbeg{}, tend{}; float tbeg{}, tend{};
if (!rshape.stroke->strokeTrim(tbeg, tend)) { tbeg = 0.0f; tend = 1.0f; } if (!rshape.stroke->strokeTrim(tbeg, tend)) { tbeg = 0.0f; tend = 1.0f; }
if (tbeg == tend) return; if (tbeg == tend) {
pbuff.decodePath(rshape, false, [&](const WgVertexBuffer& path_buff) {
appendShape(context, path_buff);
});
} else if (rshape.stroke->trim.simultaneous) {
pbuff.decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) { pbuff.decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) {
appendShape(context, path_buff); appendShape(context, path_buff);
proceedStrokes(context, rshape.stroke, tbeg, tend, path_buff); proceedStrokes(context, rshape.stroke, tbeg, tend, path_buff);
}); });
// append shape with strokes with simultaneous flag
} else { } else {
float totalLen = 0.0f; float totalLen = 0.0f;
// append shapes
pbuff.decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) { pbuff.decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) {
appendShape(context, path_buff); appendShape(context, path_buff);
totalLen += path_buff.total(); totalLen += path_buff.total();
}); });
// append strokes
float tbeg{}, tend{};
if (!rshape.stroke->strokeTrim(tbeg, tend)) { tbeg = 0.0f; tend = 1.0f; }
if (tbeg == tend) return;
float len_beg = totalLen * tbeg; // trim length begin float len_beg = totalLen * tbeg; // trim length begin
float len_end = totalLen * tend; // trim length end float len_end = totalLen * tend; // trim length end
float len_acc = 0.0; // accumulated length float len_acc = 0.0; // accumulated length
@ -395,6 +393,7 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
len_acc += len_path; len_acc += len_path;
}); });
} }
}
// update shapes bbox // update shapes bbox
updateAABB(tr); updateAABB(tr);
meshDataBBox.update(context, pMin, pMax); meshDataBBox.update(context, pMin, pMax);