{"record":{"id":"e21ca1688c5c4d74","repo":"BabylonJS/Babylon.js","slug":"cannot-create-gpu-msaa-texture-because-underlying","errorCode":null,"errorMessage":"Cannot create GPU MSAA texture because underlying GPU texture is not created yet.","messagePattern":"Cannot create GPU MSAA texture because underlying GPU texture is not created yet\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Engines/WebGPU/webgpuHardwareTexture.ts","lineNumber":143,"sourceCode":"    }\r\n\r\n    public reset(): void {\r\n        this._webgpuTexture = null;\r\n        this._webgpuMSAATexture.length = 0;\r\n        this.view = null;\r\n        this.viewForWriting = null;\r\n    }\r\n\r\n    public release(): void {\r\n        this._webgpuTexture?.destroy();\r\n        this.releaseMSAATextures();\r\n        this._copyInvertYTempTexture?.destroy();\r\n        this.reset();\r\n    }\r\n\r\n    private _createMSAATexture(samples: number, index: number): void {\r\n        if (!this._webgpuTexture) {\r\n            throw new Error(\"Cannot create GPU MSAA texture because underlying GPU texture is not created yet.\");\r\n        }\r\n\r\n        if (!this._webgpuMSAATexture) {\r\n            this._webgpuMSAATexture = [];\r\n        }\r\n\r\n        this._webgpuMSAATexture[index] = this._engine._textureHelper.createMSAATexture(this._webgpuTexture, this.originalFormat, samples);\r\n    }\r\n}\r\n","sourceCodeStart":125,"sourceCodeEnd":153,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Engines/WebGPU/webgpuHardwareTexture.ts#L125-L153","documentation":"WebGPUHardwareTexture._createMSAATexture needs a valid underlying GPUTexture to create a multisampled copy with the same size/format. If the texture has not yet been uploaded/created on the GPU (this._webgpuTexture is undefined), Babylon throws rather than silently creating an MSAA texture with wrong properties. This guards against using render-target or sampling paths before GPU resource creation completed.","triggerScenarios":"Calling engine.createTextureForCanvas / reading getMSAATexture for a texture whose GPU-side creation is deferred (e.g. data still loading, texture created with delayed GPU upload, or a dynamic/video texture not yet updated). Calling _createMSAATexture during rendering before _webgpuTexture was assigned by _createWebGPUTexture.","commonSituations":"Using a texture in a render pass with MSAA enabled before its image data finished loading; texture from a VideoTexture or DynamicTexture not yet initialized; race between texture load callback and first render with hardware-scaled MSAA render targets.","solutions":["Ensure the texture is fully created/ready before rendering with MSAA: await texture.isReady() or use the onLoadedObservable callback","Check that the texture was actually uploaded (not created with noMipmap/deferred options that skip GPU creation)","Update the code ordering so the first render happens after texture load completes","If creating a render target, ensure the RT was generated (engine.createRenderTargetTexture) before MSAA helpers access it"],"exampleFix":"// before\nengine.runRenderLoop(() => scene.render()); // texture may not be on GPU yet\n// after\ntexture.onLoadObservable.addOnce(() => {\n  engine.runRenderLoop(() => scene.render());\n});","handlingStrategy":"validation","validationCode":"if (!texture.isReady()) {\n  await new Promise(res => texture.onLoadObservable.addOnce(res)); // or await texture.isReady() where available\n}\n// only then render with MSAA / access getMSAATexture","typeGuard":"function hasGpuTexture(hw: { _webgpuTexture?: GPUTexture }): hw is { _webgpuTexture: GPUTexture } {\n  return hw._webgpuTexture != null;\n}","tryCatchPattern":"try {\n  scene.render();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('underlying GPU texture is not created yet')) {\n    await texture.isReady(); // retry next frame\n    requestAnimationFrame(() => scene.render());\n  } else throw e;\n}","preventionTips":["Always await texture readiness (isReady / onLoadObservable) before first render","Avoid mixing deferred-load textures with MSAA render passes on frame one","Log texture._webgpuTexture presence when debugging MSAA failures","Keep texture creation and first usage in the same lifecycle phase"],"tags":["webgpu","texture","msaa","initialization-order"],"backgroundTag":"gpu-texture-not-created","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}