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

+5 -9
View File
@@ -1,6 +1,6 @@
import * as Cesium from 'cesium';
import * as geo from '../geo/index.js';
import { engineFromViewer } from '../globe/cesium/engineFromViewer.js';
import { isGlobeEngine } from '../globe/contract.js';
import {
createCyberSonarSampler,
isCyberContactSonarActive as isCyberSonarActive,
@@ -2664,15 +2664,11 @@ function createDevFacade() {
/**
* Initialize the singleton host. Repeated calls for the same engine are no-op.
* @param {import('../globe/contract.js').GlobeEngine | object} target The
* globe engine, or a Cesium viewer (its engine: engineFromViewer).
* @param {import('../globe/contract.js').GlobeEngine} engine
*/
export function initWorldOverlay(target) {
const engine = engineFromViewer(target);
if (!engine)
throw new TypeError(
'initWorldOverlay requires a globe engine or a Cesium viewer',
);
export function initWorldOverlay(engine) {
if (!isGlobeEngine(engine))
throw new TypeError('initWorldOverlay requires a globe engine');
if (_engine === engine && _canvas && _removePostRender) return;
if (_engine) destroyWorldOverlay();
_destroyed = false;