Exported .riv file becomes empty/invalid after saving code in the Script Editor

Description: I’ve encountered a critical issue where an Artboard that functions correctly in the editor becomes "empty" or "invisible" in the exported .riv file after adding and saving code in the Script Editor.

Steps to Reproduce:

  1. Create an Artboard with a functioning State Machine and animations.

  2. Export the .riv file and test it in rivinspect.dev — Result: Works perfectly.

  3. Open the Script Editor for the same Artboard, paste Luau code, and press Ctrl+S to save.

  4. Export the Artboard again as a .riv file (using the same export settings).

  5. Upload the new .riv file to rivinspect.dev or any runtime viewer.

Expected Result: The exported .riv file should contain the Artboard, State Machine, and the logic as it appears in the Rive editor.

Actual Result: The viewer fails to detect any Artboards or State Machines. The file appears to be "empty" or the data structure is unrecognized by the inspector, even though the file size might suggest data exists.

Additional Notes: If I delete the script and re-export, the file returns to normal. It seems the act of saving scripts or the presence of the script data is corrupting the export header or the artboard indexing.



-- GlowTrail: Optimized Version

local MAX_POINTS = 40 -- 稍微减少点数提升性能

local SMOOTH_STEPS = 2 -- 2次平滑通常足够,3次会导致点数爆炸

local TRAIL_LAYERS = 5 -- 减少到5层,视觉差异不大但性能更好

local FADE_SPEED = 0.55

local TAIL_DECAY = 0.18

-- ─── Chaikin corner-cutting smoother ──────────────────────────────────────

local function chaikin(pts: { Vector }, passes: number): { Vector }

local result = pts

for _ = 1, passes do

local next: { Vector } = {}

if #result < 2 then

break

end

table.insert(next, result[1])

for i = 1, #result - 1 do

local a = result[i]

local b = result[i + 1]

table.insert(

next,

Vector.xy(a.x 0.75 + b.x 0.25, a.y 0.75 + b.y 0.25)

)

table.insert(

next,

Vector.xy(a.x 0.25 + b.x 0.75, a.y 0.25 + b.y 0.75)

)

end

table.insert(next, result[#result])

result = next

end

return result

end

-- ─── Build a Path (只在必要时调用) ──────────────────────────────────────────

local function updatePathGeometry(path: Path, pts: { Vector })

path:reset()

local n = #pts

if n < 2 then

return

end

path:moveTo(pts[1])

if n == 2 then

path:lineTo(pts[2])

return

end

for i = 2, n do

local p0 = pts[math.max(i - 2, 1)]

local p1 = pts[i - 1]

local p2 = pts[i]

local p3 = pts[math.min(i + 1, n)]

local cp1 = Vector.xy(p1.x + (p2.x - p0.x) / 6, p1.y + (p2.y - p0.y) / 6)

local cp2 = Vector.xy(p2.x - (p3.x - p1.x) / 6, p2.y - (p3.y - p1.y) / 6)

path:cubicTo(cp1, cp2, p2)

end

end

type GlowTrail = {

glowColor: Input<number>,

strokeWidth: Input<number>,

points: { Vector },

smoothPts: { Vector },

sharedPath: Path, -- 核心优化:所有层共用一个路径对象

paints: { Paint },

isDragging: boolean,

trailOpacity: number,

needsRebuild: boolean,

activePtr: number,

}

local function buildPaints(self: GlowTrail)

local base = self.glowColor

local r, g, b = Color.red(base), Color.green(base), Color.blue(base)

for i = 1, TRAIL_LAYERS do

local t = (i - 1) / (TRAIL_LAYERS - 1)

self.paints[i] = Paint.with({

style = 'stroke',

thickness = self.strokeWidth (1 + t 7),

color = Color.rgba(r, g, b, math.floor((1 - t 0.85) 220)),

cap = 'round',

join = 'round',

blendMode = 'screen',

})

end

end

function init(self: GlowTrail, context: Context): boolean

self.sharedPath = Path.new() -- 初始化单个路径

buildPaints(self)

return true

end

function update(self: GlowTrail)

buildPaints(self)

end

function pointerDown(self: GlowTrail, event: PointerEvent)

self.isDragging = true

self.trailOpacity = 1.0

self.activePtr = event.id

self.points = { event.position }

self.needsRebuild = true

event:hit()

end

function pointerMove(self: GlowTrail, event: PointerEvent)

if not self.isDragging or event.id ~= self.activePtr then

return

end

local pos = event.position

local pts = self.points

if #pts == 0 or Vector.distanceSquared(pos, pts[#pts]) > 9 then -- 增加距离阈值(3px^2),减少采样频率

table.insert(pts, pos)

if #pts > MAX_POINTS then

table.remove(pts, 1)

end

self.needsRebuild = true

end

event:hit()

end

function pointerUp(self: GlowTrail, event: PointerEvent)

if event.id == self.activePtr then

self.isDragging = false

end

end

function advance(self: GlowTrail, seconds: number): boolean

if not self.isDragging then

self.trailOpacity = math.max(0, self.trailOpacity - FADE_SPEED * seconds)

if #self.points > 1 then

local toRemove = math.ceil(TAIL_DECAY seconds MAX_POINTS)

for _ = 1, math.min(toRemove, #self.points - 1) do

table.remove(self.points, 1)

end

self.needsRebuild = true

end

end

if self.needsRebuild and #self.points >= 2 then

self.smoothPts = chaikin(self.points, SMOOTH_STEPS)

updatePathGeometry(self.sharedPath, self.smoothPts) -- 只在这里计算一次几何图形

self.needsRebuild = false

end

return self.trailOpacity > 0 or self.isDragging

end

function draw(self: GlowTrail, renderer: Renderer)

if #self.points < 2 or self.trailOpacity <= 0 then

return

end

-- 直接绘制已经计算好的几何图形,只切换画笔颜色

for i = TRAIL_LAYERS, 1, -1 do

local p = self.paints[i]

if self.trailOpacity < 1 then

local a = math.floor(Color.alpha(p.color) * self.trailOpacity)

renderer:drawPath(

self.sharedPath,

p:copy({ color = Color.alpha(p.color, a) })

)

else

renderer:drawPath(self.sharedPath, p)

end

end

end

return function(): Node<GlowTrail>

return {

glowColor = Color.rgba(80, 180, 255, 255),

strokeWidth = 3,

points = {},

smoothPts = {},

paints = {},

isDragging = false,

trailOpacity = 0,

needsRebuild = false,

activePtr = 0,

init = init,

update = update,

advance = advance,

draw = draw,

pointerDown = pointerDown,

pointerMove = pointerMove,

pointerUp = pointerUp,

}

end