From 1660b06064779edc9484745c949fb90bcc8f67e6 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Sun, 2 Nov 2025 13:25:21 +0100 Subject: [PATCH] fix two timers bugs --- src/App/App.tsx | 2 +- src/statecharts/interpreter.ts | 2 +- src/statecharts/timed_reactive.ts | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/App/App.tsx b/src/App/App.tsx index 8f519c1..2e4c678 100644 --- a/src/App/App.tsx +++ b/src/App/App.tsx @@ -212,7 +212,7 @@ export function App() { return () => { if (timeout) clearTimeout(timeout); } - }, [time, trace]); // <-- todo: is this really efficient? + }, [time, currentTraceItem]); // <-- todo: is this really efficient? function appendNewConfig(simtime: number, cause: string, computeNewState: () => [RaisedEvent[], CoupledState]) { let newItem: TraceItem; diff --git a/src/statecharts/interpreter.ts b/src/statecharts/interpreter.ts index 94cab86..2520187 100644 --- a/src/statecharts/interpreter.ts +++ b/src/statecharts/interpreter.ts @@ -279,7 +279,7 @@ function attemptSrcState(simtime: number, sourceState: AbstractState, event: RT_ else { // get transitions triggered by timeout triggered = labels.filter(([_t,l]) => - l.trigger.kind === "after" && l.trigger.durationMs === event.timeDurMs); + l.trigger.kind === "after" && sourceState.uid === event.state && l.trigger.durationMs === event.timeDurMs); } } else { diff --git a/src/statecharts/timed_reactive.ts b/src/statecharts/timed_reactive.ts index 87b1328..9a85379 100644 --- a/src/statecharts/timed_reactive.ts +++ b/src/statecharts/timed_reactive.ts @@ -22,7 +22,13 @@ export function statechartExecution(ast: Statechart): TimedReactive { const bigstep = initialize(ast); return [bigstep.outputEvents, bigstep]; }, - timeAdvance: (c: RT_Statechart) => (c.environment.get("_timers") as Timers)[0]?.[0] || Infinity, + timeAdvance: (c: RT_Statechart) => { + const timers = c.environment.get("_timers"); + if (timers && timers[0]) { + return timers[0][0]; + } + return Infinity; + }, intTransition: (c: RT_Statechart) => { const timers = c.environment.get("_timers") as Timers; if (timers.length === 0) {