CesiumGS / CesiumGS/cesium

Mouse over picking when polygons switch between batches causes errors

Open
#4,074 5 comments 0 reactions 0 assignees View on GitHub
category - picking category - polygons/geometry type - bug
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

I get the following error message:

```
Uncaught RuntimeError: An entity with id 26912e0a-e73c-4b55-ac1b-f1bfed18bd22 already exists in this collection.
Error
at new RuntimeError (http://localhost:8080/Source/Core/RuntimeError.js:43:19)
at EntityCollection.add (http://localhost:8080/Source/DataSources/EntityCollection.js:283:19)
at :58:32
at handleMouseMove (http://localhost:8080/Source/Core/ScreenSpaceEventHandler.js:251:13)
at HTMLDocument.listener (http://localhost:8080/Source/Core/ScreenSpaceEventHandler.js:68:13) (on line 283 of http://localhost:8080/Source/DataSources/EntityCollection.js)
```

when I run the following sandcastle examples

``` javascript
var viewer = new Cesium.Viewer('cesiumContainer', {
selectionIndicator : false,
infoBox : false
});

var scene = viewer.scene;
var handler;

var pickedEntities = new Cesium.EntityCollection();
var pickColor = Cesium.Color.YELLOW;
function makeProperty(entity, color) {
var colorProperty = new Cesium.CallbackProperty(function(time, result) {
if (pickedEntities.contains(entity)) {
return pickColor.clone(result);
}
return color.clone(result);
}, false);

entity.polygon.material = new Cesium.ColorMaterialProperty(colorProperty);
}

var red = viewer.entities.add({
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-70.0, 30.0,
-60.0, 30.0,
-60.0, 40.0,
-70.0, 40.0]),
height : 0
}
});
makeProperty(red, Cesium.Color.RED.withAlpha(0.5));

var blue = viewer.entities.add({
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-75.0, 34.0,
-63.0, 34.0,
-63.0, 40.0,
-75.0, 40.0]),
height : 0
}
});
makeProperty(blue, Cesium.Color.BLUE.withAlpha(0.5));

// Move the primitive that the mouse is over to the top.
handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
// get an array of all primitives at the mouse position
var pickedObjects = scene.drillPick(movement.endPosition);
if (Cesium.defined(pickedObjects)) {
//Update the collection of picked entities.
pickedEntities.removeAll();
for (var i = 0; i < pickedObjects.length; ++i) {
var entity = pickedObjects[i].id;
pickedEntities.add(entity);
}
}

}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
```

This occurs using `Primitive`s. If you remove the `height : 0` from both entities the same thing will occur with `GroundPrimitives`. It only happens when you force the entity to switch batches during the pick. For `Primitive` it has to switch between opaque and translucent, for `GroundPrimitive` it just has to switch color.

Contributor guide

Open the contributing guide

Research direction

Reproduce the supplied Sandcastle example and inspect the stack through Source/DataSources/EntityCollection.js and Source/Core/ScreenSpaceEventHandler.js. Compare behavior while entities switch between opaque and translucent or ground batches. Done means mouse-over picking can switch batches without the duplicate-entity RuntimeError.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.