Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-assets

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Load asset URL textures, atlases and BMFont with AssetBank. Use for refcounted disposal, extension selection, cache reuse or AIR_E_ATLAS_IN_USE/AIR_E_FNT_IN_USE cleanup.

  • 10 files
  • 88.8 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-assets

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescommon-mistakes.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from the cocosair-assets skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.

Common Mistakes

[HIGH] Assuming a resources bundle or Creator build output

Wrong:

import { resources, load, loadRemote } from 'cocosair';   // load and loadRemote are not export names
const tex = await new Promise((r, j) => resources.load('panel', Texture2D, (e, a) => e ? j(e) : r(a)));
assetManager.init({ bundleVers: { resources: '1.0' } });  // nothing reads a Creator settings file here

Correct:

import { assetManager, loadAssetAsync, Texture2D } from 'cocosair';
assetManager.assets.add('gen/panel', myTexture);          // register, then load by the same key
const tex = await loadAssetAsync('gen/panel', Texture2D);
const cfg = await loadAssetAsync('assets/panel-manifest.json');   // plain URL, no type argument

resources is an unregistered new Bundle() (src/cocos/asset/asset-manager/bundle.ts:655) whose _config has no addressable paths, so its load rejects with Bundle resources doesn't contain panel (src/cocos/asset/asset-manager/url-transformer.ts:106) while assetManager.resources is null (src/cocos/asset/asset-manager/asset-manager.ts:369-370) - the registry and the URL form are the two routes that actually resolve.

[HIGH] Treating an AbortSignal as a network cancel

Wrong:

const ctrl = new AbortController();
const p = bank.load('http://cdn/large.pkm', { ext: 'pkm', signal: ctrl.signal });
ctrl.abort();          // expecting the transfer to stop and bytes to be refunded
await p.catch(() => {});

Correct:

const ctrl = new AbortController();
const p = bank.load(url, { ext: 'png', signal: ctrl.signal });
// abort only drops this waiter; keep the promise alive and ignore the result
const asset = await p.catch((e) => { if (e.code === 'AIR_E_ABORTED') return null; throw e; });
if (asset) bank.release(url, 'png');      // release the subscription you actually took

AssetBank.underlyingCancelSupported is the literal false (src/air/assets/asset-bank.ts:148) because loadRemote has no cancellation channel at all; abort removes this waiter from the shared in-flight record (:318) and lets the request finish, balancing an orphaned result with a net-zero ref pair (:391-398), so treating it as a bandwidth or teardown mechanism leaks the load you thought you cancelled.

[HIGH] Copying the manual line that Label can only use system fonts

Wrong:

// docs/manual/creating-text.md:38-39 says AIR has no font asset pipeline
label.useSystemFont = true;                 // and stops there
const font = await loadAssetAsync('assets/game.fnt');   // wrong helper for a typed font

Correct:

const bank = new AssetBank();
const handle = await loadBitmapFont('assets/game.fnt', { bank });   // parses .fnt plus its single .png page
label.font = handle.font;          // untracked hold: no addRef from the Label setter
label.useSystemFont = false;       // the setter flips it, but be explicit at read time
// before disposing: label.font = null, then handle.dispose()

The runtime BMFont path is shipped and reachable (src/air/assets/bmfont.ts:36, :104, :132; re-exported at src/air/index.ts:32; assembler switch at src/cocos/2d/assembler/label/index.ts:34-40) - only the Creator font-asset workflow is missing, and docs/manual/bitmap-font-loading.md:1-5 documents the delivered path.

[MEDIUM] Suffix-less or trimmed-atlas URLs

Wrong:

await bank.load('https://cdn/asset');                    // throws AIR_E_EXT_REQUIRED
await bank.load('https://cdn/asset', { ext: 'image/png' }); // throws AIR_E_INVALID_EXT (a MIME type is not an ext)
await loadAtlas('pack.atlas', { bank });                 // page file listed as "hero" with no suffix
const font = createBitmapFont(data, trimmedSubFrame);    // throws AIR_E_FNT_PAGE_TEXTURE

Correct:

await bank.load('https://cdn/asset', { ext: 'png' });    // 1-16 alphanumerics; case is normalized, so 'PNG' also works
await loadAtlas('pack.atlas', { bank, pageExt: 'png' }); // explicit extension for suffix-less pages
const font = createBitmapFont(data, fullUnrotatedPage);   // frame rect 0,0,scaleW,scaleH and matching texture

ext is validated against /^[a-zA-Z0-9]{1,16}$/ and is part of the cache key (src/air/assets/asset-bank.ts:77, :94, :80-82), a suffix-less page without pageExt is rejected by the loader (src/air/assets/atlas/atlas-loader.ts:52-54), and the font factory validates the whole page (src/air/assets/bmfont.ts:105-109) - all four failures are throws with stable codes, so read the code instead of retrying the same call.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "load remote files without a Creator resources bundle",
  "the same URL returns a destroyed asset",
  "create a texture from canvas or pixel data",
  "load a sprite atlas or bitmap font",
  "an atlas or font handle refuses to dispose"
]
owns
[
  "asset-bank",
  "asset-cache",
  "reference-counting",
  "texture2d",
  "atlas",
  "bmfont"
]
not_for
[
  "glTF or GLB model loading -> cocosair-gltf",
  "bind an existing font to Label -> cocosair-ui-2d",
  "live HTML textures and DOM -> cocosair-graphics-and-dom"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "管理远程资产、AssetBank 引用计数、纹理、图集和位图字体。用于加载、缓存、取消、共享资源释放或字体导入问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-assets