PathEffect PathData vertex count is unstable‚ cubic commands appear/disappear during animation
I've hit a significant issue with PathEffect scripts and the `PathData` that gets passed to the `update` function.
The Problem
When a `PointsPath` has `StraightVertex` nodes with a corner `radius` > 0, the rendered `PathData` converts each rounded corner into `cubicTo` commands. The issue is that the number of `cubicTo` commands emitted for a single rounded corner is not stable‚ it changes frame-to-frame as vertex positions animate, even though the corner radius itself is constant (single keyframe, not animated).
In my testing with a 6-vertex polygon, the total extracted endpoint count fluctuates between 8, 9, and 10 across frames during animation. The vertex positions are animating, but the radius values are not‚ yet Rive's internal path tessellation sometimes emits 1 cubic for a corner and sometimes 2, presumably based on some arc-size threshold or optimization.
This makes it impossible to reliably map a path command index back to an editor vertex index, which is essential for things like aligning gradients to specific polygon edges.
What I need (and what I think would help others)
1. Stable vertex count in PathData. If a `PointsPath` has 6 `StraightVertex` children, the `PathData` delivered to a PathEffect should always produce a consistent, predictable number of commands per vertex‚ regardless of the arc size that frame. A rounded corner should always emit the same number of cubics (e.g., always 2), never get optimized down to 1 or 0.
2. Access to the underlying editor vertices from a PathEffect. The `update(self, path: PathData, node: NodeReadData)` signature gives us `NodeReadData`, but that type has no `children` property. If we could traverse `node.children` to read the `StraightVertex` x/y/radius values directly, we wouldn't need to reverse-engineer vertex positions from the rendered cubic arcs at all. This would be the cleanest solution.
3. Alternatively, annotate PathData commands with their source vertex index. If each `PathCommand` carried metadata indicating which editor vertex it originated from, scripts could trivially group commands by vertex and get stable indices.
Current workaround
I'm currently intersecting the tangent lines at the entry/exit of each cubic run to reconstruct the original corner position. This works but it's fragile, mathematically complex for what should be a simple "give me vertex 3's position," and shouldn't be necessary.
Repro
- Create a `PointsPath` with 6 `StraightVertex` nodes, some with `radius = 15`
- Animate the vertex x/y positions across keyframes (radius stays constant)
- Attach a PathEffect script and count the commands in `PathData` each frame
- Observe the command count changing (e.g., 8 ‚9 ‚10 ‚9 ‚8)
This is the script i use to test:
-- VertexCountRepro (PathEffect)
-- Minimal repro for Rive bug report.
-- Counts every endpoint in the PathData (moveTo, lineTo, cubicTo)
-- and prints to console whenever the count changes.
-- On a 6-vertex PointsPath with constant corner radii and
-- animated vertex positions, the count should always be the same.
-- Instead it fluctuates (e.g. 8 → 9 → 10) because Rive
-- emits a variable number of cubicTo commands per rounded corner.
--
-- Usage: attach as PathEffect to any stroke/fill on the path.
-- Play the animation and watch the console.
type VertexCountRepro = {
ctx: Context?,
lastCount: number,
}
function init(self: VertexCountRepro, context: Context): boolean
self.ctx = context
self.lastCount = -1
return true
end
function advance(self: VertexCountRepro, seconds: number): boolean
if self.ctx then
self.ctx:markNeedsUpdate()
end
return true
end
function update(self: VertexCountRepro, path: PathData, node: NodeReadData): PathData
-- Count every endpoint — the simplest possible extraction
local endpoints = 0
local moveTos = 0
local lineTos = 0
local cubicTos = 0
local closes = 0
for i = 1, #path do
local cmd = path[i]
if cmd.type == "moveTo" then
endpoints += 1
moveTos += 1
elseif cmd.type == "lineTo" then
endpoints += 1
lineTos += 1
elseif cmd.type == "cubicTo" then
endpoints += 1
cubicTos += 1
elseif cmd.type == "close" then
closes += 1
end
end
if endpoints ~= self.lastCount then
print("[VertexCountRepro] CHANGED: "
.. tostring(self.lastCount) .. " → " .. tostring(endpoints)
.. " (moveTo=" .. tostring(moveTos)
.. " lineTo=" .. tostring(lineTos)
.. " cubicTo=" .. tostring(cubicTos)
.. " close=" .. tostring(closes) .. ")")
self.lastCount = endpoints
end
return path
end
return function(): PathEffect<VertexCountRepro>
return {
lastCount = -1,
init = init,
advance = advance,
update = update,
}
end