CesiumGS / CesiumGS/cesium

Crash in PolylineGraphics

Open
#5,345 1 comment 0 reactions 0 assignees View on GitHub
category - polyline type - bug
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

I have following code:

```
var pickPositions = [];
var lineStrip;
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(movement) {
if (!viewer.scene.pickPositionSupported) {
console.warn("pickPosition not supported!");
return;
}

var pickedPosition = viewer.scene.pickPosition(movement.position);

if (pickedPosition !== undefined) {
pickPositions.push(pickedPosition);

if (pickPositions.length > 1) {
//viewer.entities.remove(lineStrip); //<- add this line here and all works fine

lineStrip = viewer.entities.add({
polyline : {
positions: pickPositions,
width : 10,
material: Cesium.Color.ROYALBLUE,
followSurface: true
}
});
}
}
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
```

At the moment I picked 5. point Cesium is crashing. I'm getting following error:
```
RangeError: Invalid array length
RangeError: Invalid array length
at Function.PolylineGeometry.unpack (http://localhost:8080/Source/Core/PolylineGeometry.js:248:35)
at createPolylineGeometry (http://localhost:8080/Source/Workers/createPolylineGeometry.js:14:49)
at createGeometry (http://localhost:8080/Source/Workers/createGeometry.js:46:30)
at http://localhost:8080/Source/Workers/createTaskProcessorWorker.js:56:42
```
It works if I remove `lineStrip` each time before adding new `lineStrip`. So it looks like Cesium isn't handling changes in position array correctly (I have no idea why it crashes at 5 points, but not already at 3).

My expectation was an error message that altering position after it is already added to scene is not allowed - or if altering is supported no crash.

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the provided entity and changing pickPositions array. Start with Source/Core/PolylineGeometry.js at unpack and follow the calls through Source/Workers/createPolylineGeometry.js and createGeometry.js. Done means changing the positions after adding the polyline no longer crashes, or produces the expected error behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.