Skip to content

Commit d8fcde4

Browse files
committed
When using CanvasTexture.refresh or Graphics.generateTexture it would throw WebGL warnings like 'bindTexture: Attempt to bind a deleted texture'. This was due to the Frames losing sync with the glTexture reference used by their TextureSource. Fix phaserjs#4050
1 parent a17b0c2 commit d8fcde4

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* `TextureTintPipeline.batchTexture` has a new optional argument `skipFlip` which allows you to control the internal render texture flip Y check.
5151
* The Device.OS check for `node` will now do a `typeof` first to avoid issues with rollup packaged builds needing to shim the variable out. Fix #4058 (thanks @hollowdoor)
5252
* Arcade Physics Bodies will now sync the display origin of the parent Game Object to the body properties as part of the `updateBounds` call. This means if you change the origin of an AP enabled Game Object, after creation of the body, it will be reflected in the body position. This may or may not be a breaking change for your game. Previously it was expected that the origin should always be 0.5 and you adjust the body using `setOffset`, but this change makes a bit more sense logically. If you find that your bodies are offset after upgrading to this version then this is likely why. Close #4052 (thanks @SolarOmni)
53+
* The `Texture.getFramesFromTextureSource` method has a new boolean argument `includeBase`, which defaults to `false` and allows you to set if the base frame should be returned into the array or not.
5354

5455
### Bug Fixes
5556

@@ -60,6 +61,8 @@
6061
* The `Shape.Line` object was missing a `lineWidth` property unless you called the `setLineWidth` method, causing the line to not render in Canvas only. Fix #4068 (thanks @netgfx)
6162
* All parts of Matter Body now have the `gameObject` property set correctly. Previously only the first part of the Body did.
6263
* When using `MatterGameObject` and `fromVerts` as the shape type it wouldn't pass the values to `Bodies.fromVertices` because of a previous conditional. It now passes them over correctly and the body is only set if the result is valid.
64+
* The `Texture.getFramesFromTextureSource` method was returning an array of Frame names by mistake, instead of Frame references. It now returns the Frames themselves.
65+
* When using `CanvasTexture.refresh` or `Graphics.generateTexture` it would throw WebGL warnings like 'bindTexture: Attempt to bind a deleted texture'. This was due to the Frames losing sync with the glTexture reference used by their TextureSource. Fix #4050 (thanks @kanthi0802)
6366

6467
### Examples, Documentation and TypeScript
6568

src/gameobjects/graphics/Graphics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,9 +1493,9 @@ var Graphics = new Class({
14931493
// var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix, renderTargetCtx, allowClip)
14941494
this.renderCanvas(renderer, this, 0, Graphics.TargetCamera, null, ctx, false);
14951495

1496-
if (renderer.gl && texture)
1496+
if (texture)
14971497
{
1498-
texture.source[0].glTexture = renderer.canvasToTexture(ctx.canvas, texture.source[0].glTexture);
1498+
texture.refresh();
14991499
}
15001500
}
15011501

src/renderer/webgl/WebGLRenderer.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,19 +1817,21 @@ var WebGLRenderer = new Class({
18171817
{
18181818
var gl = this.gl;
18191819

1820-
if (dstTexture)
1821-
{
1822-
this.deleteTexture(dstTexture);
1823-
}
1824-
18251820
var wrapping = gl.CLAMP_TO_EDGE;
18261821

18271822
if (IsSizePowerOfTwo(srcCanvas.width, srcCanvas.height))
18281823
{
18291824
wrapping = gl.REPEAT;
18301825
}
18311826

1832-
return this.createTexture2D(0, gl.NEAREST, gl.NEAREST, wrapping, wrapping, gl.RGBA, srcCanvas, srcCanvas.width, srcCanvas.height, true);
1827+
var newTexture = this.createTexture2D(0, gl.NEAREST, gl.NEAREST, wrapping, wrapping, gl.RGBA, srcCanvas, srcCanvas.width, srcCanvas.height, true);
1828+
1829+
if (newTexture && dstTexture)
1830+
{
1831+
this.deleteTexture(dstTexture);
1832+
}
1833+
1834+
return newTexture;
18331835
},
18341836

18351837
/**

src/textures/TextureSource.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ var TextureSource = new Class({
235235
if (this.renderer.gl && this.isCanvas)
236236
{
237237
this.glTexture = this.renderer.canvasToTexture(this.image, this.glTexture);
238+
239+
// Update all the Frames using this TextureSource
240+
241+
var index = this.texture.getTextureSourceIndex(this);
242+
243+
var frames = this.texture.getFramesFromTextureSource(index, true);
244+
245+
for (var i = 0; i < frames.length; i++)
246+
{
247+
frames[i].glTexture = this.glTexture;
248+
}
238249
}
239250
},
240251

0 commit comments

Comments
 (0)