pixijs / gif

Plugin to support playback of animated GIF images in PixiJS.
https://pixijs.io/gif/docs/
MIT License
41 stars 5 forks source link

"Uncaught Error: Frame index out of range" unless TARGET_FPMS is set #11

Closed spencerflem closed 1 year ago

spencerflem commented 2 years ago

I'm getting an issue where unless I set TARGET_FPMS to a number, the frame index does not get set correctly and it errors out. I suspect this is caused by the line const elapsed = this.animationSpeed * deltaTime / (settings.TARGET_FPMS as number); which if TARGET_FMPS is not set would cause elapsed to be undefined, poisoning the frame index.

I just recently switched to pixijs 7.0.0-alpha.3 and gif 2.0.0 and this error seems new to that. Looking at the code though I'm not sure why this hasn't happened before, as settings.TARGET_FPMS seems like it has been undefined for a little while at least.

The docs for 7.0.0-alpha3 state that TARGET_FPMS has a Default Value of 0.06 but in this minimal test case, I'm getting undefined for both v7 and v6.5.2

import { settings } from '@pixi/settings'
console.log(settings.TARGET_FPMS)

Anyways, hopefully this helps. If there's a right way to fix this, I'm happy to make a pull request. Otherwise, settings.TARGET_FPMS = 0.06; is a perfectly good workaround so no worries if this gets closed or something.

spencerflem commented 1 year ago

Ok - found out TARGET_FMPS is set here: https://github.com/pixijs/pixijs/blob/db824181dc3dfffa0951fb8579282ba8e654cb3b/packages/ticker/src/settings.ts

So it was just because I never imported Ticker

so alternative (better) workaround is to import that