Hi,
Again, I'm new to Cesium, so here's a spoiler for nub questions
I'm getting the above error ("Developer Error: must call update before calling getGeometryInstanceAttributes").
Here's my code:
/*********************** Code Starts ***************************/
// create or update polygons (50/50 chance)
function addOrUpdate(){
function createNewPolygon(){
// Create the polygon geometry.
function getCoordinateValue(diff, base){
return Math.random()*diff-base;
}
var positions = Cesium.Cartesian3.fromDegreesArray([
getCoordinateValue(50, -115.0), getCoordinateValue(15, 35),
getCoordinateValue(50, -115.0), getCoordinateValue(15, 35),
getCoordinateValue(50, -115.0), getCoordinateValue(15, 35),
getCoordinateValue(50, -115.0), getCoordinateValue(15, 35),
getCoordinateValue(50, -115.0), getCoordinateValue(15, 35)
]);
// Create a geometry instance using the polygon geometry.
var polygonInstance = new Cesium.GeometryInstance({
geometry : Cesium.PolygonGeometry.fromPositions({
positions : positions,
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
}),
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(
Cesium.Color.fromRandom({alpha : 1.0})
)
},
id: viewer.scene.primitives._primitives.length
});
return polygonInstance;
}
function updateExistingPolygon(){
var primitives = viewer.scene.primitives._primitives;
var index = Math.round(Math.random()*(primitives.length-1));
var chosenPrimitive = primitives[index];
var attributes = chosenPrimitive.getGeometryInstanceAttributes(index);
attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.fromRandom({alpha : 1.0}));
}
var newPolygons = ;
if (Math.random()<0.5)
newPolygons.push(createNewPolygon());
else
updateExistingPolygon();
}
viewer = new Cesium.Viewer(elm.attr('id'));
setInterval(addOrUpdate(), 1000, 5);
/*********************** Code Ends ***************************/
The line:
var attributes = chosenPrimitive.getGeometryInstanceAttributes(index);
The code roughly works, only once in a while it gives the above error (it sometimes succeeds for the same id, only to fail later, and then succeeds again for that same id).
Any idea why?
Couldn't find much about this error...