refactor(overlays): hand the shell's overlay host the engine, not the viewer

The controls pass the scene engine to the shell, which initializes the
world overlay on it; initWorldOverlay takes only a globe engine (a viewer
or null is refused), so the shell no longer needs a viewer for its
overlay. engineFromViewer only returns the engine registered for a viewer
(the scene engine until teardown) and never builds one, so no engine can
outlive its viewer without a destroy path. Overlay and detection tests
and the allocation worker build a Cesium engine on their mock viewers and
destroy it with them; frame allocation is unchanged.
This commit is contained in:
German Khokhlov committed 2026-10-15 18:53:57 +04:00
1 parent 3e3aa0bd9f
commit 12c9651a67
10 files changed
+145 -105

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
// controls.js and the shell import browser-only UI modules, so these read the
// source: the scene engine is threaded to the shell, which hands it (not the
// viewer) to the world overlay. initWorldOverlay itself is tested on the fake
// engine without a viewer (src/overlays/worldOverlay.test.mjs).
const read = (relative) =>
readFileSync(new URL(relative, import.meta.url), 'utf8');
test('the controls pass the scene engine to the shell', () => {
const controls = read('./controls.js');
assert.match(controls, /scene: \{ viewer, engine, mapStackController, operations \}/);
assert.match(controls, /new Controls\(viewer, \{[\s\S]*?\n\s+engine,\n/);
});
test('the shell initializes the world overlay on its engine', () => {
const shell = read('../ui/applicationShell.js');
assert.match(shell, /\{\n\s+engine = null,\n\s+mapStackController = null,/);
assert.match(shell, /initWorldOverlay\(engine\);/);
assert.doesNotMatch(shell, /initWorldOverlay\(viewer\)/);
});