Skip to content

fix: invalidate in-flight fillCache work on idle()/dispose() - #48

Open
PriyeshPandey2000 wants to merge 1 commit into
diffusionstudio:mainfrom
PriyeshPandey2000:fix/video-idle-dispose-generation
Open

fix: invalidate in-flight fillCache work on idle()/dispose()#48
PriyeshPandey2000 wants to merge 1 commit into
diffusionstudio:mainfrom
PriyeshPandey2000:fix/video-idle-dispose-generation

Conversation

@PriyeshPandey2000

@PriyeshPandey2000 PriyeshPandey2000 commented Sep 1, 2026

Copy link
Copy Markdown

Summary

  • VideoBuffer.idle()/dispose() (video.ts) and SequenceDecoder.idle()/dispose() (sequence.ts) tear down the iterator/cache/queue without bumping seekGeneration. Every other mutation site (scrubTo, exactSeekTo) increments it — these two don't, so a fillCache already in flight never notices the teardown happened.
  • Two consequences:
    • Crash: fillCache's loop re-reads this.iterator each iteration; if idle()/dispose() lands mid-await and nulls it, the generation check that should catch this passes (unchanged), so the loop calls .next() on nullTypeError: Cannot read properties of null (reading 'next').
    • Leak: even without the crash, a decoded frame can still land in frameCallbackcache.insert() after dispose(). FrameCache.insert()resizeCaches() resurrects the atlas/source canvases dispose() explicitly zeroed out to free — undoing the teardown.
  • Fix: bump seekGeneration in idle()/dispose() in both files, same pattern already used at the two seek entry points.
  • Added a vitest regression test (video.test.ts) reproducing the exact crash — fails with the reported TypeError pre-fix, passes post-fix.

Test plan

  • cd packages/runtime && npx vitest run — 2/2 pass, reproduces the exact reported TypeError pre-fix on unpatched code
  • npx tsc --noEmit — clean (one pre-existing unrelated error in packages/assets)

idle() and dispose() tear down the iterator/cache/queue without
bumping seekGeneration, so a fillCache already in flight never
notices — it reads next() off the now-nulled iterator (crash) or
inserts a decoded frame into the disposed cache, resurrecting the
canvas backing store dispose() was meant to free. Same shape in
sequence.ts.

Bump seekGeneration in idle()/dispose() in both files, matching the
existing pattern at scrubTo/exactSeekTo. Add a regression test that
reproduces the exact crash pre-fix.
@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

@PriyeshPandey2000 is attempting to deploy a commit to the Diffusion Studio Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant