Skip to content

Commit 5d00fca

Browse files
committed
Safer implementation, handle edge cases as done previously
1 parent 08ecab0 commit 5d00fca

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

packages/engine/Source/DataSources/BillboardVisualizer.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function EntityData(entity) {
4141
this.entity = entity;
4242
this.billboard = undefined;
4343
this.textureValue = undefined;
44+
this.subRegion = undefined;
4445
}
4546

4647
/**
@@ -128,10 +129,12 @@ BillboardVisualizer.prototype.update = function (time) {
128129
billboard.id = entity;
129130
item.billboard = billboard;
130131
item.textureValue = undefined;
132+
item.subRegion = undefined;
131133
}
132134

133135
billboard.show = show;
134-
if (item.textureValue !== textureValue) {
136+
const imageUpdated = item.textureValue !== textureValue;
137+
if (imageUpdated) {
135138
billboard.image = textureValue;
136139
item.textureValue = textureValue;
137140
}
@@ -232,13 +235,16 @@ BillboardVisualizer.prototype.update = function (time) {
232235
time,
233236
boundingRectangleScratch,
234237
);
235-
if (
236-
defined(subRegion) &&
237-
!BoundingRectangle.equals(subRegion, item.subRegion)
238-
) {
239-
billboard.setImageSubRegion(billboard.image, subRegion);
238+
const subRegionUpdated = !BoundingRectangle.equals(
239+
subRegion,
240+
item.subRegion,
241+
);
242+
if (subRegionUpdated) {
240243
item.subRegion = BoundingRectangle.clone(subRegion, item.subRegion);
241244
}
245+
if (defined(subRegion) && (imageUpdated || subRegionUpdated)) {
246+
billboard.setImageSubRegion(billboard.image, subRegion);
247+
}
242248
}
243249
return true;
244250
};

packages/engine/Source/Scene/BillboardTexture.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ BillboardTexture.prototype.addImageSubRegion = async function (id, subRegion) {
268268
return;
269269
}
270270

271+
if (this._id !== id) {
272+
// Another load was initiated and resolved resolved before this one. This operation is cancelled.
273+
return;
274+
}
275+
271276
if (!defined(index) || index === -1) {
272277
this._loadState = BillboardLoadState.FAILED;
273278
this._index = -1;

0 commit comments

Comments
 (0)