diff --git a/src/rendering/cubismoffscreenrendertarget_webgl.ts b/src/rendering/cubismoffscreenrendertarget_webgl.ts index d1efae0..1bb2254 100644 --- a/src/rendering/cubismoffscreenrendertarget_webgl.ts +++ b/src/rendering/cubismoffscreenrendertarget_webgl.ts @@ -204,8 +204,10 @@ export class CubismOffscreenRenderTarget_WebGL extends CubismRenderTarget_WebGL } public release(): void { + const borrowedFromManager = this._webGLOffscreenManager != null; + if ( - this._webGLOffscreenManager != null && + borrowedFromManager && this._gl != null && this._renderTexture != null ) { @@ -215,13 +217,17 @@ export class CubismOffscreenRenderTarget_WebGL extends CubismRenderTarget_WebGL ); } - if (this._colorBuffer && this._gl) { - this._gl.deleteTexture(this._colorBuffer); + if (borrowedFromManager) { + // Color buffer and framebuffer are borrowed from CubismWebGLOffscreenManager. + // The manager owns GPU lifetime (releaseStaleRenderTextures / context teardown). + // Deleting them here double-frees the pool slot and can delete previousFramebuffer + // when setOffscreenRenderTarget stored it as a fallback. this._colorBuffer = null; - } - if (this._renderTexture && this._gl) { - this._gl.deleteFramebuffer(this._renderTexture); this._renderTexture = null; + } else if (this._gl) { + // Inherited createRenderTarget() locally owns the texture/FBO + // (_modelRenderTargets). destroyRenderTarget() is the matching owner. + this.destroyRenderTarget(); } if (this._webGLOffscreenManager != null) { diff --git a/src/rendering/cubismrenderer_webgl.ts b/src/rendering/cubismrenderer_webgl.ts index 9520878..293ebe7 100644 --- a/src/rendering/cubismrenderer_webgl.ts +++ b/src/rendering/cubismrenderer_webgl.ts @@ -741,7 +741,8 @@ export class CubismRenderer_WebGL extends CubismRenderer { for (let i = 0; i < this._offscreenList.length; i++) { if (this._offscreenList[i] != null && this._offscreenList[i].isValid()) { - this._offscreenList[i].destroyRenderTarget(); + // プールから借用した GPU オブジェクトは destroy しない + this._offscreenList[i].release(); } } this._offscreenList.length = 0;