fix(embed): an inline panel's timer frames move the camera, take input and run the clock again

When a host stops animation frames, the panel drew from a timer with the
viewer's render(): the camera's flight and input, the clock's tick, then a
draw if due. Through the frame port it called renderNow(), which on Cesium
only forced a draw, so flights stood still, drags and zooms did nothing
and the clock stopped. renderNow takes {ifDue: true}: one tick of the
loop as its own would run it, drawing only a frame that is due (the
widget's render() on Cesium; the stub's tick without a forced request).
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:43:13 -08:00
1 parent f4beb676ae
commit 03a7d8827a
9 files changed
+86 -22

No files matched your search

+12 -8
View File
@@ -103,19 +103,23 @@ export function willDraw(scene, time) {
}
/**
* The contract's `renderNow` on `scene`: draw a frame at `time` even when
* nothing asked for one, and throw the error Cesium caught and raised on
* `renderError` when the frame failed.
* @param {object} scene
* @param {object} [time] A Cesium JulianDate.
* The contract's `renderNow` on `owner`'s scene: draw a frame at the
* clock's time even when nothing asked for one, or with `ifDue` run one
* frame of the widget's own loop (`render()`: the camera's flight and
* input, the clock's tick, then a draw if one is due); throw the error
* Cesium caught and raised on `renderError` when the frame failed.
* @param {object} owner A Cesium `Viewer` or `CesiumWidget`.
* @param {{ifDue?: boolean}} [options]
*/
export function renderNow(scene, time) {
export function renderNow(owner, { ifDue = false } = {}) {
const scene = owner.scene;
let failure = null;
const off = scene.renderError?.addEventListener((_scene, error) => {
failure ??= { error };
});
try {
scene.forceRender(time);
if (ifDue) owner.render();
else scene.forceRender(owner.clock?.currentTime);
} finally {
off?.();
}
@@ -259,7 +263,7 @@ export function createSceneFrame(viewer) {
viewer.useDefaultRenderLoop = suspended ? false : ownLoop;
if (!suspended && !gone()) scene.requestRender();
},
renderNow: () => renderNow(scene, viewer.clock?.currentTime),
renderNow: (options) => renderNow(viewer, options),
renderOnce({ timeoutMs } = {}) {
if (gone()) return Promise.resolve();
return new Promise((resolve, reject) => {
+31 -2
View File
@@ -202,8 +202,37 @@ test('renderNow throws the error Cesium raises on renderError', () => {
if (fail) for (const cb of listeners) cb(scene, failure);
},
};
renderNow(scene);
const owner = { scene, clock: { currentTime: 'now' } };
renderNow(owner);
fail = true;
assert.throws(() => renderNow(scene), failure);
assert.throws(() => renderNow(owner), failure);
assert.equal(listeners.size, 0, 'it stops listening either way');
});
test('renderNow ifDue runs a frame of the widget’s own loop, as its render() does', () => {
const listeners = new Set();
const failure = new Error('worker failed');
const calls = [];
let fail = false;
const scene = {
renderError: {
addEventListener: (cb) => (listeners.add(cb), () => listeners.delete(cb)),
},
forceRender: () => calls.push('forceRender'),
};
// The widget's render(): the camera's flight and input, the clock's
// tick, then a draw if one is due.
const owner = {
scene,
clock: { currentTime: 'now' },
render() {
calls.push('render');
if (fail) for (const cb of listeners) cb(scene, failure);
},
};
renderNow(owner, { ifDue: true });
assert.deepEqual(calls, ['render']);
fail = true;
assert.throws(() => renderNow(owner, { ifDue: true }), failure);
assert.equal(listeners.size, 0);
});
+1 -1
View File
@@ -348,7 +348,7 @@ export function createCesiumPorts(
if (!suspended) scene.requestRender();
},
// Draws even when nothing asked for a frame; throws when it fails.
renderNow: () => renderNow(scene, widget.clock.currentTime),
renderNow: (options) => renderNow(widget, options),
renderOnce: (options) => nextPostRender(options),
setTargetFps(fps) {
targetFps = fps > 0 ? fps : 0;