Skip to content

Commit

Permalink
dont use the pool for CanvasRenderTarget
Browse files Browse the repository at this point in the history
as they can use different canvas attributes
  • Loading branch information
obiot committed Aug 14, 2024
1 parent 9886e87 commit e6b7ad4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/melonjs/src/particles/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import pool from "../system/legacy_pool.js";
import ParticleEmitterSettings from "./settings.js";
import { randomFloat } from "./../math/math.ts";
import Container from "./../renderable/container.js";
import CanvasRenderTarget from "../video/rendertarget/canvasrendertarget.js";

/**
* @ignore
*/
function createDefaultParticleTexture(w = 8, h = 8) {
const defaultParticleTexture = pool.pull("CanvasRenderTarget", w, h, {
const defaultParticleTexture = new CanvasRenderTarget(w, h, {
offscreenCanvas: true,
});

Expand Down
4 changes: 3 additions & 1 deletion packages/melonjs/src/renderable/light2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ellipsePool } from "./../geometries/ellipse.ts";
import { colorPool } from "./../math/color.ts";
import pool from "../system/legacy_pool.js";
import Renderable from "./renderable.js";
import CanvasRenderTarget from "../video/rendertarget/canvasrendertarget.js";

/**
* additional import for TypeScript
Expand Down Expand Up @@ -142,7 +143,7 @@ export default class Light2d extends Renderable {
);

/** @ignore */
this.texture = pool.pull("CanvasRenderTarget", this.width, this.height, {
this.texture = new CanvasRenderTarget(this.width, this.height, {
offscreenCanvas: false,
});

Expand Down Expand Up @@ -194,6 +195,7 @@ export default class Light2d extends Renderable {
colorPool.release(this.color);
this.color = undefined;
pool.push(this.texture);
this.texture.destroy();
this.texture = undefined;
ellipsePool.release(this.visibleArea);
this.visibleArea = undefined;
Expand Down
4 changes: 3 additions & 1 deletion packages/melonjs/src/renderable/text/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Renderable from "../renderable.js";
import { nextPowerOfTwo } from "../../math/math.ts";
import setContextStyle from "./textstyle.js";
import TextMetrics from "./textmetrics.js";
import CanvasRenderTarget from "../../video/rendertarget/canvasrendertarget.js";

/*
* ASCII Table
Expand Down Expand Up @@ -173,7 +174,7 @@ export default class Text extends Renderable {

// the canvas Texture used to render this text
// XXX: offscreenCanvas is currently disabled for text rendering due to issue in WebGL mode
this.canvasTexture = pool.pull("CanvasRenderTarget", 2, 2, {
this.canvasTexture = new CanvasRenderTarget(2, 2, {
offscreenCanvas: false,
});

Expand Down Expand Up @@ -403,6 +404,7 @@ export default class Text extends Renderable {
}
globalRenderer.cache.delete(this.canvasTexture.canvas);
pool.push(this.canvasTexture);
this.canvasTexture.destroy();
this.canvasTexture = undefined;
colorPool.release(this.fillStyle);
colorPool.release(this.strokeStyle);
Expand Down

0 comments on commit e6b7ad4

Please sign in to comment.