From c324261445a3669f4f3cedde5ecad362cf962d4b Mon Sep 17 00:00:00 2001 From: Matt Karl Date: Wed, 6 Mar 2024 18:44:19 -0500 Subject: [PATCH] Fix: Workaround v8 bug with setting filters (#447) --- examples/src/DemoApplication.mjs | 45 ++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/examples/src/DemoApplication.mjs b/examples/src/DemoApplication.mjs index 7f9bde4c4..0ec32f606 100644 --- a/examples/src/DemoApplication.mjs +++ b/examples/src/DemoApplication.mjs @@ -96,7 +96,6 @@ export default class DemoApplication extends PIXI.Application // Setup the container this.pond = new PIXI.Container(); this.pond.filterArea = this.filterArea; - this.pond.filters = this.pondFilters; this.stage.addChild(this.pond); // Setup the background image @@ -208,8 +207,6 @@ export default class DemoApplication extends PIXI.Application this.events.emit('animate', delta, animateTimer); - this.pond.filters = this.pondFilters; - if (!this.animating) { return; @@ -224,7 +221,6 @@ export default class DemoApplication extends PIXI.Application const fish = this.fishes[i]; fish.direction += fish.turnSpeed * 0.01; - fish.filters = this.fishFilters; fish.x += Math.sin(fish.direction) * fish.speed; fish.y += Math.cos(fish.direction) * fish.speed; @@ -302,28 +298,45 @@ export default class DemoApplication extends PIXI.Application // https://github.com/orgs/pixijs/projects/2/views/4?pane=issue&itemId=48582986 const toggleFilter = (enabled) => { - if (enabled) + if (options.fishOnly) { - if (options.fishOnly) + const fishFilters = [...this.fishFilters]; + + if (enabled) { - this.fishFilters.push(filter); + fishFilters.push(filter); } else { - this.pondFilters.push(filter); - } - } - else if (options.fishOnly) - { - const index = this.fishFilters.indexOf(filter); + const index = fishFilters.indexOf(filter); - if (index !== -1) this.fishFilters.splice(index, 1); + if (index !== -1) fishFilters.splice(index, 1); + } + this.fishFilters = fishFilters; + this.fishes.forEach((fish) => + { + fish.filters = fishFilters; + }); } else { - const index = this.pondFilters.indexOf(filter); + const pondFilters = [...this.pondFilters]; + + if (enabled) + { + pondFilters.push(filter); + } + else + { + const index = pondFilters.indexOf(filter); + + if (index !== -1) pondFilters.splice(index, 1); + } - if (index !== -1) this.pondFilters.splice(index, 1); + this.pondFilters = pondFilters; + // TODO: seems like a bug, requiring invalidation + this.pond.filters = []; + this.pond.filters = pondFilters; } };