delivering-imported-textures
Delivering imported textures
Overview
The import → send → release dance is library code, not app code. @napolab/texture-bridge-core/electron ships it. Hand-rolling it is where paint-texture leaks and double-release crashes come from.
Pick the altitude — do not hand-roll any of them
| What you hold | Call | Target argument |
|---|---|---|
A TextureBridge, and want every paint frame in a window |
bridge.forwardFrames(target, { extraArgs }) — @napolab/texture-bridge-renderer |
WebContents |
A TextureInfo — from your own paint handler, a receiver, anywhere |
forwardSharedTexture(textureInfo, target, extraArgs?) — @napolab/texture-bridge-core/electron |
WebContents |
An imported texture handed to you already imported, with no TextureInfo in reach |
sendImportedTexture(frame, imported, extraArgs?) — @napolab/texture-bridge-core/electron |
WebFrameMain (webContents.mainFrame) |
Climb as high as you can. Holding a TextureInfo and calling importSharedTexture yourself so you can use sendImportedTexture is a downgrade: forwardSharedTexture does the import, checks the target, releases on every path, and reports the outcome as a ForwardDefect ({ reason: "target-destroyed" } | { reason: "import-failed"; cause } | { reason: "send-failed"; cause }) — so you never write an import try/catch, a destroyed-target guard, or a release branch. Reach for sendImportedTexture only when the import already happened outside your control.
The two target arguments differ on purpose: forwardSharedTexture takes the WebContents (it resolves and null-checks mainFrame itself); sendImportedTexture takes the frame.
forwardSharedTexture reports, it does not throw or reject: no try/catch, and in a neverthrow pipeline it is ResultAsync.fromSafePromise, not fromPromise. Inspect the resolved defect or discard it — that is the whole failure surface.