Skip to content

Commit c324261

Browse files
authored
Fix: Workaround v8 bug with setting filters (#447)
1 parent 600305c commit c324261

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

examples/src/DemoApplication.mjs

+29-16
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export default class DemoApplication extends PIXI.Application
9696
// Setup the container
9797
this.pond = new PIXI.Container();
9898
this.pond.filterArea = this.filterArea;
99-
this.pond.filters = this.pondFilters;
10099
this.stage.addChild(this.pond);
101100

102101
// Setup the background image
@@ -208,8 +207,6 @@ export default class DemoApplication extends PIXI.Application
208207

209208
this.events.emit('animate', delta, animateTimer);
210209

211-
this.pond.filters = this.pondFilters;
212-
213210
if (!this.animating)
214211
{
215212
return;
@@ -224,7 +221,6 @@ export default class DemoApplication extends PIXI.Application
224221
const fish = this.fishes[i];
225222

226223
fish.direction += fish.turnSpeed * 0.01;
227-
fish.filters = this.fishFilters;
228224
fish.x += Math.sin(fish.direction) * fish.speed;
229225
fish.y += Math.cos(fish.direction) * fish.speed;
230226

@@ -302,28 +298,45 @@ export default class DemoApplication extends PIXI.Application
302298
// https://github.com/orgs/pixijs/projects/2/views/4?pane=issue&itemId=48582986
303299
const toggleFilter = (enabled) =>
304300
{
305-
if (enabled)
301+
if (options.fishOnly)
306302
{
307-
if (options.fishOnly)
303+
const fishFilters = [...this.fishFilters];
304+
305+
if (enabled)
308306
{
309-
this.fishFilters.push(filter);
307+
fishFilters.push(filter);
310308
}
311309
else
312310
{
313-
this.pondFilters.push(filter);
314-
}
315-
}
316-
else if (options.fishOnly)
317-
{
318-
const index = this.fishFilters.indexOf(filter);
311+
const index = fishFilters.indexOf(filter);
319312

320-
if (index !== -1) this.fishFilters.splice(index, 1);
313+
if (index !== -1) fishFilters.splice(index, 1);
314+
}
315+
this.fishFilters = fishFilters;
316+
this.fishes.forEach((fish) =>
317+
{
318+
fish.filters = fishFilters;
319+
});
321320
}
322321
else
323322
{
324-
const index = this.pondFilters.indexOf(filter);
323+
const pondFilters = [...this.pondFilters];
324+
325+
if (enabled)
326+
{
327+
pondFilters.push(filter);
328+
}
329+
else
330+
{
331+
const index = pondFilters.indexOf(filter);
332+
333+
if (index !== -1) pondFilters.splice(index, 1);
334+
}
325335

326-
if (index !== -1) this.pondFilters.splice(index, 1);
336+
this.pondFilters = pondFilters;
337+
// TODO: seems like a bug, requiring invalidation
338+
this.pond.filters = [];
339+
this.pond.filters = pondFilters;
327340
}
328341
};
329342

0 commit comments

Comments
 (0)