-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't share geometry arrays between Batch and Primitive #8569
Conversation
…Primitive constructor. In the batches, the `geometries` is a live reference to the array inside the AssociativeArray owned by the batch. We need to make a copy of the array so that subsequent changes to the batch don't affect the Primitive's view of the instances, which could happen during async creation or combining.
Thanks for the pull request @shunter!
Reviewers, don't forget to make sure that:
|
Here's the Sandcastle test case copied from #5947 var viewer = new Cesium.Viewer('cesiumContainer');
var entities = [];
var i;
for (i = 0; i < 100; ++i) {
entities.push(viewer.entities.add({
polyline: {
positions : Cesium.Cartesian3.fromDegreesArray([-75, i/2,
-125, i/4])
}
}));
}
function removeEntity() {
console.log(viewer.entities.removeById(entities[entities.length-1].id));
}
var originalPrimitiveUpdate = Cesium.Primitive.prototype.update;
var updateCount = 0;
Cesium.Primitive.prototype.update = function(frameState) {
originalPrimitiveUpdate.apply(this, arguments);
if (updateCount === 0) {
removeEntity();
}
updateCount++;
}; |
Thanks @shunter Will look at this right now. |
By right now, I mean this afternoon of course. |
Reading the linked issue and trying to job my memory, but I can't think of a single reason we would ever have intentionally shared these arrays. I think making a copy is the right things to do here. |
@shunter just to throw out another thought, would it make more sense for Primitive to copy during construction? I guess this is kind of a CesiumJS design decision we made a long time ago for performance reasons, we never copy arrays unless absolutely needed. So if that's still the pattern we follow, I'll merge this. Just figured it was worth a separate comment first. |
Update CHANGES |
I thought about putting the defensive copy inside the Primitive constructor, but that would introduce an extra redundant copy in the numerous cases where we are passing a temporary array into the constructor. |
I updated CHANGES. |
Yeah, that's what I figured. Thanks @shunter! |
Make a copy of the array of geometry instances before passing to the Primitive constructor.
In the batches,
geometries
is a live reference to the array inside the AssociativeArray, which is owned by the batch. We need to make a copy of the array so that subsequent changes to the batch don't affect the Primitive's view of the instances, which could happen during async creation or combining.Fixes #5947
I marked this next release because the crash in #5947 is consistently affecting a customer application so I would like to get this looked at for 1.66.