fix: VM trigger only fires once in script hosted artboard (#13096) c7ec04d45d
Fixes [#13052] — in a file using a shader/GPU-canvas script that hosts an artboard, a view model trigger only fires once. (Verified the attached rev works as expected after the fixes)

Root cause
Triggers are re-armed by the per-frame ViewModelInstanceValue::advanced() reset. #13002 moved that reset for script-created (detached) VM instances out of the inner artboard's advance and into an end-of-frame hook on StateMachineInstance::advanceAndApply. Two gaps:

Editor: the editor drives frames from Dart and never calls advanceAndApply, so the end-of-frame reset never ran. After the first transition consumed the trigger, its used-in-layer mark was never cleared → fires once, dead forever.
Idle scripts: once a scripted drawable's advance loop parks (advance returns false), no input event re-arms it. A pointer-fired trigger is then never consumed by the inner state machine, and the end-of-frame sweep wipes the pending fire one frame later.
Fix
Expose ScriptingContext::advanceDetachedViewModels() to Dart (riveLuaAdvanceDetachedViewModels, FFI + WASM) and call it at the end of RiveFile.advance — the editor mirror of the runtime's end-of-frame hook.
Add ScriptedDrawable::wakeAdvance() (re-arm m_isAdvanceActive + Paint dirt), invoked after dispatching pointer/keyboard/text/gamepad events to a script, in both C++ and the Dart editor mirror. Guarantees the inner state machine consumes an input-fired trigger before the end-of-frame reset. Matches the existing re-arm pattern in didHydrateScriptInputs.

Co-authored-by: Philip Chung <philterdesign@gmail.com>
diff --git a/.rive_head b/.rive_head
index a484a67..e32dc7a 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-9ebf0f88df7a292be01f95fcf6e3ccf0abe07954
+c7ec04d45d085a3133b31c51413aa2819751a474
diff --git a/include/rive/scripted/scripted_drawable.hpp b/include/rive/scripted/scripted_drawable.hpp
index 312f3c0..0076862 100644
--- a/include/rive/scripted/scripted_drawable.hpp
+++ b/include/rive/scripted/scripted_drawable.hpp
@@ -66,6 +66,10 @@
                   bool isPressed,
                   bool isRepeat);
     bool textInput(const std::string& text);
+    // Re-arm the advance loop after an input event is dispatched to the
+    // script; the handler may have changed state (e.g. fired a trigger on a
+    // scripted artboard) that only the next scriptAdvance can consume.
+    void wakeAdvance();
 
 private:
     bool m_isAdvanceActive = true;
diff --git a/src/scripted/scripted_drawable.cpp b/src/scripted/scripted_drawable.cpp
index 61d6fdc..c970825 100644
--- a/src/scripted/scripted_drawable.cpp
+++ b/src/scripted/scripted_drawable.cpp
@@ -137,6 +137,7 @@
         rive_lua_pop(L, 1);
     }
     rive_lua_pop(L, 1);
+    wakeAdvance();
     return true;
 }
 
@@ -182,6 +183,7 @@
             rive_lua_pop(state, 1);
         }
         hitResult = pointerEvent->m_hitResult;
+        m_drawable->wakeAdvance();
     }
     rive_lua_pop(state, 1);
     return hitResult;
@@ -253,6 +255,7 @@
     }
     // Stack: [self]
     rive_lua_pop(L, 1);
+    wakeAdvance();
     return shouldStopPropagation;
 }
 
@@ -302,6 +305,7 @@
     }
     // Stack: [self]
     rive_lua_pop(L, 1);
+    wakeAdvance();
     return shouldStopPropagation;
 }
 
@@ -350,6 +354,12 @@
     }
 }
 
+void ScriptedDrawable::wakeAdvance()
+{
+    m_isAdvanceActive = true;
+    addScriptedDirt(ComponentDirt::Paint);
+}
+
 Core* ScriptedDrawable::hitTest(HitInfo*, const Mat2D&) { return nullptr; }
 
 StatusCode ScriptedDrawable::onAddedDirty(CoreContext* context)
diff --git a/tests/unit_tests/runtime/scripting/scripting_wake_advance_test.cpp b/tests/unit_tests/runtime/scripting/scripting_wake_advance_test.cpp
new file mode 100644
index 0000000..ec3b150
--- /dev/null
+++ b/tests/unit_tests/runtime/scripting/scripting_wake_advance_test.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2026 Rive
+ */
+
+// A scripted drawable whose advance() has gone idle (returned false) must be
+// re-armed when an input event is dispatched to it: the handler may have
+// changed state (e.g. fired a trigger on a scripted artboard) that only the
+// next scriptAdvance can consume — before the end-of-frame detached view
+// model reset wipes it. See rive-app/rive#13052.
+
+#include "catch.hpp"
+#include "scripting_test_utilities.hpp"
+#include "rive/lua/rive_lua_libs.hpp"
+#include "rive/scripted/scripted_drawable.hpp"
+
+using namespace rive;
+
+namespace
+{
+// Stubs addScriptedDirt so the test doesn't need a full artboard graph.
+class WakeTestScriptedDrawable : public ScriptedDrawable
+{
+public:
+    bool addScriptedDirt(ComponentDirt value, bool recurse = false) override
+    {
+        return true;
+    }
+};
+
+int readCounter(lua_State* L, const char* getter)
+{
+    lua_getglobal(L, getter);
+    REQUIRE(lua_pcall(L, 0, 1, 0) == LUA_OK);
+    int value = (int)lua_tonumber(L, -1);
+    lua_pop(L, 1);
+    return value;
+}
+
+constexpr const char* wakeScript =
+    R"(type MyDrawing = {}
+local advanceCount = 0
+local pointerDownCount = 0
+local keyCount = 0
+
+function init(self: MyDrawing, context: Context): boolean
+  return true
+end
+
+function advance(self: MyDrawing, seconds: number): boolean
+  advanceCount += 1
+  return false -- idle immediately
+end
+
+function pointerDown(self: MyDrawing, event: PointerEvent)
+  pointerDownCount += 1
+end
+
+function keyboardEvent(self: MyDrawing, event: KeyboardEvent): boolean
+  keyCount += 1
+  return false
+end
+
+function getAdvanceCount(): number
+  return advanceCount
+end
+
+function getPointerDownCount(): number
+  return pointerDownCount
+end
+
+function getKeyCount(): number
+  return keyCount
+end
+
+return function(): Node<MyDrawing>
+  return {
+    init = init,
+    advance = advance,
+    pointerDown = pointerDown,
+    keyboardEvent = keyboardEvent,
+  }
+end
+)";
+
+constexpr AdvanceFlags advanceFlags = AdvanceFlags::Animate |
+                                      AdvanceFlags::NewFrame |
+                                      AdvanceFlags::AdvanceNested;
+
+// Runs the script's advance once (returns false), then verifies the loop is
+// parked: further advances no longer reach the script.
+void parkAdvanceLoop(WakeTestScriptedDrawable& drawable, lua_State* L)
+{
+    int before = readCounter(L, "getAdvanceCount");
+    drawable.advanceComponent(0.016f, advanceFlags);
+    CHECK(readCounter(L, "getAdvanceCount") == before + 1);
+    drawable.advanceComponent(0.016f, advanceFlags);
+    CHECK(readCounter(L, "getAdvanceCount") == before + 1);
+}
+} // namespace
+
+TEST_CASE("pointer event re-arms an idle scripted drawable's advance loop",
+          "[scripting]")
+{
+    ScriptingTest vm(wakeScript);
+    lua_State* L = vm.state();
+
+    WakeTestScriptedDrawable drawable;
+    // advances (1 << 0) + wantsPointerDown (1 << 3)
+    drawable.implementedMethods((1 << 0) | (1 << 3));
+    drawable.setAsset(make_rcp<ScriptAsset>());
+    REQUIRE(drawable.ensureScriptInitialized(vm.vm()));
+
+    parkAdvanceLoop(drawable, L);
+
+    // Dispatch a pointer event through the hit component.
+    HitScriptedDrawable hit(&drawable, nullptr);
+    hit.processEvent(Vec2D(1.0f, 1.0f), ListenerType::down, true, 0.0f, 0);
+    CHECK(readCounter(L, "getPointerDownCount") == 1);
+
+    // The event re-armed the loop: the next frame advances the script again.
+    drawable.advanceComponent(0.016f, advanceFlags);
+    CHECK(readCounter(L, "getAdvanceCount") == 2);
+}
+
+TEST_CASE("keyboard event re-arms an idle scripted drawable's advance loop",
+          "[scripting]")
+{
+    ScriptingTest vm(wakeScript);
+    lua_State* L = vm.state();
+
+    WakeTestScriptedDrawable drawable;
+    // advances (1 << 0) + wantsKeyboardInput (1 << 16)
+    drawable.implementedMethods((1 << 0) | (1 << 16));
+    drawable.setAsset(make_rcp<ScriptAsset>());
+    REQUIRE(drawable.ensureScriptInitialized(vm.vm()));
+
+    parkAdvanceLoop(drawable, L);
+
+    drawable.keyInput(Key::a, KeyModifiers::none, true, false);
+    CHECK(readCounter(L, "getKeyCount") == 1);
+
+    drawable.advanceComponent(0.016f, advanceFlags);
+    CHECK(readCounter(L, "getAdvanceCount") == 2);
+}