diff --git a/modules/core/src/lifecycle/prop-types.ts b/modules/core/src/lifecycle/prop-types.ts index 6a734e4c63b..55b8d9f3cd8 100644 --- a/modules/core/src/lifecycle/prop-types.ts +++ b/modules/core/src/lifecycle/prop-types.ts @@ -202,13 +202,13 @@ const TYPE_DEFINITIONS = { if (!context || !context.gl) { return null; } - return createTexture(context.gl, value, { + return createTexture(component.id, context.gl, value, { ...propType.parameters, ...component.props.textureParameters }); }, - release: value => { - destroyTexture(value); + release: (value, propType: ImagePropType, component) => { + destroyTexture(component.id, value); } } } as const; diff --git a/modules/core/src/utils/texture.ts b/modules/core/src/utils/texture.ts index 27ec100c368..503e5413bbc 100644 --- a/modules/core/src/utils/texture.ts +++ b/modules/core/src/utils/texture.ts @@ -9,9 +9,10 @@ const DEFAULT_TEXTURE_PARAMETERS: Record = { }; // Track the textures that are created by us. They need to be released when they are no longer used. -const internalTextures: Record = {}; +const internalTextures: Record = {}; export function createTexture( + owner: string, gl: WebGLRenderingContext, image: any, parameters: Record @@ -43,15 +44,16 @@ export function createTexture( } }); // Track this texture - internalTextures[texture.id] = true; + internalTextures[texture.id] = owner; return texture; } -export function destroyTexture(texture: Texture2D) { +export function destroyTexture(owner: string, texture: Texture2D) { if (!texture || !(texture instanceof Texture2D)) { return; } - if (internalTextures[texture.id]) { + // Only delete the texture if requested by the same layer that created it + if (internalTextures[texture.id] === owner) { texture.delete(); delete internalTextures[texture.id]; } diff --git a/modules/extensions/src/fill-style/fill-style-extension.ts b/modules/extensions/src/fill-style/fill-style-extension.ts index 4dfa99a2d9a..fcea9a86c3d 100644 --- a/modules/extensions/src/fill-style/fill-style-extension.ts +++ b/modules/extensions/src/fill-style/fill-style-extension.ts @@ -185,8 +185,7 @@ export default class FillStyleExtension extends LayerExtension) { - const {patternTexture, emptyTexture} = this.state; - patternTexture?.delete(); + const {emptyTexture} = this.state; emptyTexture?.delete(); } diff --git a/test/modules/extensions/fill-style.spec.js b/test/modules/extensions/fill-style.spec.js index 82b58da6d92..e750c1fa229 100644 --- a/test/modules/extensions/fill-style.spec.js +++ b/test/modules/extensions/fill-style.spec.js @@ -50,6 +50,15 @@ test('FillStyleExtension#PolygonLayer', t => { t.notOk(strokeLayer.state.emptyTexture, 'should not be enabled in PathLayer'); t.notOk('fill_patternMask' in uniforms, 'should not be enabled in PathLayer'); } + }, + { + title: `Finalizing a sublayer should not affect the parent layer's loaded props`, + updateProps: { + data: [] + }, + onAfterUpdate: ({layer}) => { + t.ok(layer.props.fillPatternAtlas.handle, 'fillPatternAtlas texture is not deleted'); + } } ];