Skip to content

Commit

Permalink
Do not destroy primitives that are already destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
rropp5 committed Dec 14, 2023
1 parent 2189e16 commit f0b36e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/engine/Source/DataSources/EntityCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,28 @@ EntityCluster.prototype.update = function (frameState) {
}
};

/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
* If this object was destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
*
* @returns {boolean} True if this object was destroyed; otherwise, false.
*
* @see EntityCluster#destroy
*/
EntityCluster.prototype.isDestroyed = function () {
return false;
};

/**
* Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
* release of WebGL resources, instead of relying on the garbage collector to destroy this object.
* <p>
* Unlike other objects that use WebGL resources, this object can be reused. For example, if a data source is removed
* from a data source collection and added to another.
* </p>
* As a result, this object is not destroyed in this function.
*/
EntityCluster.prototype.destroy = function () {
this._labelCollection =
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/Source/Scene/PrimitiveCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ PrimitiveCollection.prototype.remove = function (primitive) {

delete primitive._external._composites[this._guid];

if (this.destroyPrimitives) {
if (this.destroyPrimitives && !primitive.isDestroyed()) {
primitive.destroy();
}

Expand All @@ -209,7 +209,7 @@ PrimitiveCollection.prototype.remove = function (primitive) {
*/
PrimitiveCollection.prototype.removeAndDestroy = function (primitive) {
const removed = this.remove(primitive);
if (removed && !this.destroyPrimitives) {
if (removed && !this.destroyPrimitives && !primitive.isDestroyed()) {
primitive.destroy();
}
return removed;
Expand Down

0 comments on commit f0b36e6

Please sign in to comment.