Fix PFL VU meter trying to update after it's killed.
This commit is contained in:
parent
a82f68e89f
commit
c1a4724e99
1 changed files with 5 additions and 3 deletions
|
@ -30,18 +30,19 @@ export function VUMeter(props: VUMeterProps) {
|
|||
const FPS = 30; // Limit the FPS so that lower spec machines have a better time juggling CPU.
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true; // This VU exists as we're calling useEffect
|
||||
const animate = () => {
|
||||
if (!isMic || isMicOpen) {
|
||||
if ((!isMic || isMicOpen) && isMounted) {
|
||||
const result = audioEngine.getLevels(
|
||||
props.source,
|
||||
props.stereo ? props.stereo : false
|
||||
);
|
||||
setPeakL(result[0]);
|
||||
if (props.stereo) {
|
||||
if (props.stereo && isMounted) {
|
||||
setPeakR(result[1]);
|
||||
}
|
||||
setTimeout((current = rafRef.current, a = animate) => {
|
||||
current = requestAnimationFrame(a);
|
||||
if (isMounted) current = requestAnimationFrame(a);
|
||||
}, 1000 / FPS);
|
||||
}
|
||||
};
|
||||
|
@ -49,6 +50,7 @@ export function VUMeter(props: VUMeterProps) {
|
|||
rafRef.current = requestAnimationFrame(animate);
|
||||
}
|
||||
return () => {
|
||||
isMounted = false; // Tell the async stuff above to not bother if the VU meter has gone away.
|
||||
if (rafRef.current !== null) {
|
||||
cancelAnimationFrame(rafRef.current);
|
||||
rafRef.current = null;
|
||||
|
|
Loading…
Reference in a new issue