pmndrs / pmndrs/three-stdlib

`mergeBufferGeometries` give error for empty array

Open
#331 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
858
Forks
144
PR merge metrics
No merged PRs in 30d

Description

  • three version: 0.160
  • @types/three version:
  • three-stdlib version:
Problem description:

mergeBufferGeometries gives error Uncaught TypeError: Cannot read properties of undefined (reading 'index')
It is from some sloppy list access

https://github.com/pmndrs/three-stdlib/blame/45e22a1b636241147934e8bd9f22d506ccfc3cf0/src/utils/BufferGeometryUtils.ts#L27

which also exists in three.js upstream

https://github.com/mrdoob/three.js/blob/de6dd45d7e5aa58fed0fbc1dbe53def3402b39cc/examples/jsm/utils/BufferGeometryUtils.js#L109C20-L109C51

Relevant code:
Suggested solution:

I generally would return some reasonable identity object for such cases than raising sloppy errors.
Maybe null can be reasonable.

Or otherwise, it may be useful to denote the types as [BufferGeometry, ...BufferGeometry[]] instead of BufferGeometry[],
where typescript can just warn users that users should pass array with at least one element.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/utils/BufferGeometryUtils.ts at mergeBufferGeometries and reproduce the empty-array call that triggers the undefined-index TypeError. Compare the linked upstream three.js implementation, settle the intended empty-input behavior, and ensure the runtime behavior and TypeScript signature consistently communicate that result.

Written by the indexing model from the issue text.

Assessment

Tech stack
threejs, typescript
Domain
computer-graphics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.