mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
setBase: the last call wins; an overtaken or disposed one changes nothing
A vector setBase awaited its style before changing anything, with no generation guard, so a slow earlier call landed over a later one, and one in flight at disposal rejected. Cesium and the stub now count calls like setPhotoreal and setTerrain, abort the overtaken style load, and resolve an overtaken call with imagery: [] and settled: false.
This commit is contained in:
1 parent
5fae3cf485
commit
72d8dd606d
6 files changed
+196
-7
No files matched your search
@@ -1418,14 +1418,42 @@ export function createStubRenderer(options = {}) {
|
||||
// `surfaceIdentity`: bumped by whatever changes what heights answer against.
|
||||
let surfaceVersion = 0;
|
||||
let terrainKey = 'null';
|
||||
// The last `setBase` wins; its style load in flight, if any.
|
||||
let baseGen = 0;
|
||||
let baseLoad = null;
|
||||
const globe = {
|
||||
async setBase(base) {
|
||||
log('globe', 'setBase', [base]);
|
||||
if (base.vector && !capabilities.has('vectorBase'))
|
||||
throw new TypeError('This renderer draws no vector base');
|
||||
const gen = ++baseGen;
|
||||
baseLoad?.abort();
|
||||
baseLoad = null;
|
||||
const current = () => gen === baseGen && !destroyed;
|
||||
// Superseded (or destroyed) before its base changes: nothing changes.
|
||||
const superseded = () => ({
|
||||
photoreal: photorealStatus,
|
||||
imagery: [],
|
||||
settled: false,
|
||||
});
|
||||
if (destroyed) return superseded();
|
||||
// The style is loaded, as a renderer drawing it loads it, so one that
|
||||
// fails changes nothing; the stub paints none of it.
|
||||
if (base.vector) await loadVectorStyle(base.vector.styleUrl);
|
||||
if (base.vector) {
|
||||
const load = new AbortController();
|
||||
baseLoad = load;
|
||||
try {
|
||||
await loadVectorStyle(base.vector.styleUrl, undefined, {
|
||||
signal: load.signal,
|
||||
});
|
||||
} catch (error) {
|
||||
if (!current()) return superseded();
|
||||
throw error;
|
||||
} finally {
|
||||
if (baseLoad === load) baseLoad = null;
|
||||
}
|
||||
if (!current()) return superseded();
|
||||
}
|
||||
for (const layer of imageryLayers.slice()) layer.remove();
|
||||
if (base.photoreal !== undefined)
|
||||
await globe.setPhotoreal(base.photoreal);
|
||||
@@ -1781,6 +1809,9 @@ export function createStubRenderer(options = {}) {
|
||||
// A flight in progress ends cancelled and gives back its input hold.
|
||||
camera.endFlight();
|
||||
destroyed = true;
|
||||
baseGen += 1;
|
||||
baseLoad?.abort();
|
||||
baseLoad = null;
|
||||
if (options.container) canvas.remove?.();
|
||||
for (const clear of onceTimers) clear();
|
||||
onceTimers.clear();
|
||||
|
||||
Reference in new issue
Block a user