Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Prevent LinePrimitive scene entities from crashing with empty `point…
Browse files Browse the repository at this point in the history
…s` (#4661)

**User-Facing Changes**
- prevent LinePrimitive scene entities from crashing when `points` is
empty and not a loop

**Description**
- prevent LinePrimitive scene entities from crashing when `points` is
empty and not a loop
- add test case to SceneEntities story

<!-- link relevant github issues -->
<!-- add `docs` label if this PR requires documentation updates -->
  • Loading branch information
snosenzo committed Oct 18, 2022
1 parent 3517c03 commit 6ba7384
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class RenderableLines extends RenderablePrimitive {
this._lines.length = 0;

for (const primitive of lines) {
if (primitive.points.length === 0) {
continue;
}
const line = this._makeLine(primitive);
const group = new THREE.Group().add(line);
group.position.set(
Expand Down Expand Up @@ -111,6 +114,8 @@ export class RenderableLines extends RenderablePrimitive {
}

const positions = getPositions(primitive);
// setPosition requires the position array to be >= 6 length or else it will error
// we skip primitives with empty points before calling this function
geometry.setPositions(positions);

const singleColor = this.userData.settings.color
Expand Down Expand Up @@ -151,7 +156,7 @@ export class RenderableLines extends RenderablePrimitive {
? primitive.points.length >>> 1
: isLoop
? primitive.points.length
: primitive.points.length - 1;
: Math.max(primitive.points.length - 1, 0);

line.userData.pickingMaterial = pickingMaterial;
return line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ function makeStoryScene({
),
indices: rearrange(new Array(10).fill(0).map((_, i) => i)),
},
{
// empty points
type,
pose: xyzrpyToPose([1, 1.8 + typeIndex * 0.2, 0], [0, 0, 0]),
thickness: 5,
scale_invariant: true,
points: [],
color: makeColor("#7995fb", 0.8),
colors: [],
indices: [],
},
],
),

Expand Down

0 comments on commit 6ba7384

Please sign in to comment.