/texture-bridge:delivering-imported-texturesfrom texture-bridge
Provides safe, leak-free GPU texture delivery from Electron main process to renderer using @napolab/texture-bridge-core. Covers forwardSharedTexture, sendImportedTexture, and exactly-once release patterns.
Ships in texture-bridge. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
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.
| 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.
That subpath exports exactly forwardSharedTexture, sendImportedTexture, and the ForwardDefect type. Electron's sharedTexture namespace comes from "electron", never from this package.
How every other export in the library fails — and which ones need a wrapper: see the handling-texture-bridge-failures skill.
import { sendImportedTexture } from "@napolab/texture-bridge-core/electron";
// frame — a WebFrameMain (win.webContents.mainFrame), NOT the WebContents.
// imported — yours until this call; the library owns it afterwards.
// extraArgs — arrive verbatim as trailing args in receiver.consume()'s handler.
await sendImportedTexture(win.webContents.mainFrame, imported, [slot]);
Three properties are the reason this exists:
imported in a finally — exactly once, on success, on rejection, and on a synchronous throw from sendSharedTexture. You never release it yourself; a second release throws.async function, so calling it never throws synchronously — a throw inside becomes a rejection. ResultAsync.fromPromise(sendImportedTexture(...), toError) is the entire neverthrow integration: both failure channels are already funneled into one promise.e.texture.release() for a paint texture, closeNativeHandle(handle) for a receiver handle — once, right after your own importSharedTexture call returns, because Electron keeps its own duplicated / retained reference and never adopts yours.Best-effort call site (never awaited by a paint-rate hot path, never an unhandled rejection):
void ResultAsync.fromPromise(sendImportedTexture(frame, imported, [slot]), toError).match(
() => undefined,
(error) => onDropped(error), // or () => undefined for a silently best-effort sink
);
| Mistake | Reality |
|---|---|
import { sharedTexture } from "@napolab/texture-bridge-core/electron" | Fabrication. sharedTexture is Electron's own namespace, from "electron". |
Calling importSharedTexture yourself, on a TextureInfo you already hold, to feed sendImportedTexture | One altitude too low. forwardSharedTexture(textureInfo, webContents, extraArgs) is the whole function. |
A manual imported.release() branch for "the target died between import and send" | That branch exists only because you imported too early. forwardSharedTexture checks the target first and reports { reason: "target-destroyed" }. |
Passing webContents.mainFrame to forwardSharedTexture | It takes the WebContents. Only sendImportedTexture takes the frame. |
try/catch around forwardSharedTexture, or hand-building a { reason: "send-failed" } in that catch | It resolves defects, never rejects. The catch is dead code that invents failures the library already modeled. |
Writing importSharedTexture + sendSharedTexture + release() in two modules and noting the duplication | That duplication is the bug this export removed. Import the helper. |
.andTee(release).orTee(release) / matching try/catch pairs to prove exactly-once release | Already guaranteed inside. Deleting your tee pair removes the double-release risk with it. |
Result.fromThrowable around the send "in case it throws synchronously" | An async function cannot. One ResultAsync.fromPromise covers both channels. |
await sendSharedTexture(...); imported.release(); | Not a finally — the first failure leaks a texture per frame until the shared-texture pool starves and paint stops. |
try { imported.release() } catch {} | A single valid release does not throw. Swallowing here hides a real double-release. |
Releasing imported after handing it to sendImportedTexture | Double release. Hand-off is transfer of ownership. |
Passing win.webContents as sendImportedTexture's first argument | It takes win.webContents.mainFrame. |
awaiting delivery inside a paint handler before releasing the paint texture | The send is already dispatched before the first await; awaiting only pins the paint texture for an IPC round-trip. |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub naporin0624/electron-texture-bridge --plugin texture-bridge8 skills in this plugin
/choosing-texture-bridge-apiUse when deciding which @napolab/texture-bridge API tier to use for a feature — simple vs core, Syphon/Spout output vs in-app preview/monitor, forwardSharedTexture vs forwardFrames — when reviewing an integration plan that uses the library, or when unsure whether a texture-bridge function, method, or option actually exists./diagnosing-dead-frame-forwardsUse when forwarded frames stop arriving — a preview or monitor window that goes black or shows a "no signal" placeholder, a multiviewer deck frozen on its last frame, previews that die during a long session or for only some targets while Syphon/Spout output keeps working, a forwardFrames registration you suspect never delivered anything, or a dead preview with nothing in the logs./handling-texture-bridge-failuresUse when adding error handling, telemetry, or crash-safety to code that uses @napolab/texture-bridge — deciding whether a call needs a try/catch or a Result.fromThrowable wrapper, reviewing the failure handling of a texture-bridge integration, defining error classes for bridge or receiver operations, or diagnosing silently black output or a main-process crash from a bridge call./managing-frame-forward-lifecycleUse when registering or tearing down `TextureBridge.forwardFrames` targets — a monitor/multiviewer window the user can close and reopen, decks connected and disconnected repeatedly, a bridge disposed while forwards are still registered — or when about to add "destroyed"/"closed" listener bookkeeping, removeListener hygiene, isDestroyed guards, or try/catch around `forward.dispose()`, or when chasing a MaxListenersExceededWarning or a leak around forwarding./migrating-to-forward-framesUse when replacing an existing Electron preview/monitor implementation with @napolab/texture-bridge zero-copy forwarding — capturePage polling, paint-event bitmap IPC, toBitmap/toPNG transfers, or a Syphon loopback feeding an in-app window — or when upgrading to the release that ships forwardFrames / forwardSharedTexture./receiving-shared-texturesUse when implementing the receiving side of @napolab/texture-bridge shared-texture frames in an Electron renderer — consuming forwardFrames/forwardSharedTexture output, displaying createSharedTextureReceiver frames, building a multiviewer/preview grid, or debugging leaked VideoFrames, black canvases, or frames from a disconnected source reappearing.Other plugins' skills for the same job