Skip to content

Commit

Permalink
fix: FillGradient leak (pixijs#11061)
Browse files Browse the repository at this point in the history
* Update FillGradient.ts

* add a test
  • Loading branch information
GoodBoyDigital authored Nov 17, 2024
1 parent 0ebb05d commit 3d6cffa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/scene/graphics/shared/fill/FillGradient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export class FillGradient implements CanvasGradient
// TODO move to the system!
public buildLinearGradient(): void
{
if (this.texture) return;

const defaultSize = FillGradient.defaultTextureSize;

const { gradientStops } = this;
Expand Down
16 changes: 15 additions & 1 deletion tests/graphics/GraphicsFill.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Color } from '../../src/color/Color';
import { Texture } from '../../src/rendering/renderers/shared/texture/Texture';
import { FillGradient } from '../../src/scene/graphics/shared/fill/FillGradient';
import { FillPattern } from '../../src/scene/graphics/shared/fill/FillPattern';
import { toStrokeStyle } from '../../src/scene/graphics/shared/utils/convertFillInputToFillStyle';
import { toFillStyle, toStrokeStyle } from '../../src/scene/graphics/shared/utils/convertFillInputToFillStyle';

import type { ConvertedStrokeStyle } from '../../src/scene/graphics/shared/FillTypes';

Expand Down Expand Up @@ -152,4 +152,18 @@ describe('convertStrokeInputToStrokeStyle', () =>
matrix: gradient.transform
});
});

it('should only build FillGradient once', () =>
{
const defaultStyle = getDefaultValue();
const gradient = new FillGradient(0, 0, 200, 0);

toFillStyle(gradient, defaultStyle);

const texture = gradient.texture;

toFillStyle(gradient, defaultStyle);

expect(texture).toBe(gradient.texture);
});
});

0 comments on commit 3d6cffa

Please sign in to comment.