Open rymdmetafor opened 1 year ago
I'm getting the same error.
I'm also experiencing this error, though only when I use sprites.
This was driving me bananas, I tried a few things, and this ended up solving it - I wrapped the state-controlled volume variable in a ref. I'm not exactly sure why that helped - but now it doesn't throw the exception when changing the volume variable. I still have issues with HotModuleReplacement in Vite when using a sound sprite, every other save throws the exception.
const [volume, setVolume] = useState(.5);
const volumeRef = useRef(volume);
const [playSound] = useSound(mySoundFile, {
volume: volumeRef.current,
sprite: {
thank: [105, 50],
goodness: [287, 84],
this: [650, 70],
worked: [900, 40],
},
});
This was driving me bananas, I tried a few things, and this ended up solving it - I wrapped the state-controlled volume variable in a ref. I'm not exactly sure why that helped - but now it doesn't throw the exception when changing the volume variable.
const [volume, setVolume] = useState(.5); const volumeRef = useRef(volume); const [playSound] = useSound(mySoundFile, { volume: volumeRef.current, sprite: { thank: [105, 50], goodness: [287, 84], this: [650, 70], worked: [900, 40], }, });
When I do this and add logic to update the ref when volume changes, it errors-out again.
When having a variable set the volume of the useSound hook, sometimes changing the variable changes the volume, but sometimes it throws this error:
Uncaught TypeError: Cannot read properties of undefined (reading '0') at Howl.rate (howler.js:1564:1) at index.ts:94:1 at commitHookEffectListMount (react-dom.development.js:23150:1) at commitPassiveMountOnFiber (react-dom.development.js:24926:1) at commitPassiveMountEffects_complete (react-dom.development.js:24891:1) at commitPassiveMountEffects_begin (react-dom.development.js:24878:1) at commitPassiveMountEffects (react-dom.development.js:24866:1) at flushPassiveEffectsImpl (react-dom.development.js:27039:1) at flushPassiveEffects (react-dom.development.js:26984:1) at commitRootImpl (react-dom.development.js:26935:1)
"volume" is a useState variable. But if I make it a normal variable and change the value of it it gives me the same error. The error message seems to be about the "rate". I have tried setting a playbackrate but it did not resolve the issue. The error appears when the "volume" variable changes, but not every time. When logging the type of the "volume" variable before the declaration of the useSound hook, it returns "number", not "undefined".