`mergeBufferGeometries` give error for empty array

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

Nobody has claimed this yet.

Assessment

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

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.

Description

bug
  • 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.

Dominant language
JavaScript
Stars
863
Forks
146
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

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.

More from pmndrs/three-stdlib

All issues in pmndrs/three-stdlib

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.