Skip to content

Document IndexBuffer storage can be ArrayBuffer or typed array#8988

Merged
mvaligursky merged 1 commit into
mainfrom
mv-indexbuffer-storage-docs
Jun 30, 2026
Merged

Document IndexBuffer storage can be ArrayBuffer or typed array#8988
mvaligursky merged 1 commit into
mainfrom
mv-indexbuffer-storage-docs

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Closes #5869.

IndexBuffer stores its initialData by reference. The GLB parser passes typed arrays (Uint8/16/32Array) as initial data, while other callers pass an ArrayBuffer, so storage (and lock()) can be either form. The JSDoc previously documented only ArrayBuffer, which is what the reporter ran into. Per discussion on the issue, the agreed fix is to document the actual contract rather than copy data or add new API surface.

Changes:

  • Document the constructor's initialData as {ArrayBuffer|ArrayBufferView}, noting it is stored by reference (a typed array that is a view into a larger buffer is kept as-is).
  • Document lock() as returning {ArrayBuffer|ArrayBufferView}, advising callers to use ArrayBuffer.isView to distinguish the two.
  • Document setData()'s data param likewise (internal @ignore method).
  • Fix a typo in the constructor's @example (UInt16Array -> Uint16Array).

API Changes:

  • No runtime/behavior change. The generated type declarations now reflect the wider types: lock(): ArrayBuffer | ArrayBufferView and initialData?: ArrayBuffer | ArrayBufferView.

The GLB parser passes typed arrays as IndexBuffer initial data, while other
callers pass an ArrayBuffer, so storage/lock() can be either. Update the JSDoc
for the constructor's initialData, lock() return, and setData() to reflect this,
and fix a typo in the constructor example (UInt16Array -> Uint16Array).

Closes #5869
@github-actions

Copy link
Copy Markdown

Build size report

This PR does not change the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2269.2 KB — 584.1 KB — 453.9 KB —
playcanvas.min.mjs 2266.6 KB — 583.2 KB — 453.4 KB —

@github-actions

Copy link
Copy Markdown

Public API report

This PR changes the public API surface (+2 / −2), per the docs' rules (@ignore / @Private / undocumented are excluded).

Show API diff
-IndexBuffer.constructor(graphicsDevice: GraphicsDevice, format: number, numIndices: number, usage?: number, initialData?: ArrayBuffer, options?: { storage: boolean })
+IndexBuffer.constructor(graphicsDevice: GraphicsDevice, format: number, numIndices: number, usage?: number, initialData?: ArrayBuffer | ArrayBufferView<ArrayBufferLike>, options?: { storage: boolean })
-IndexBuffer.lock(): ArrayBuffer
+IndexBuffer.lock(): ArrayBuffer | ArrayBufferView<ArrayBufferLike>

Informational only — this never fails the build.

@mvaligursky mvaligursky merged commit 2e5d1f1 into main Jun 30, 2026
10 checks passed
@mvaligursky mvaligursky deleted the mv-indexbuffer-storage-docs branch June 30, 2026 13:15
mvaligursky added a commit that referenced this pull request Jun 30, 2026
The GLB parser passes typed arrays as IndexBuffer initial data, while other
callers pass an ArrayBuffer, so storage/lock() can be either. Update the JSDoc
for the constructor's initialData, lock() return, and setData() to reflect this,
and fix a typo in the constructor example (UInt16Array -> Uint16Array).

Closes #5869

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GLB parser incorrect index buffer construction

1 participant