mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-15 07:42:23 +00:00
Release Navara overlay targets and sprite images on repeated globe switches
This commit is contained in:
1 parent
160e445677
commit
14f7b32537
4 files changed
+118
-1
No files matched your search
@@ -217,7 +217,14 @@ function atlasTexture(atlas, encoded, onLoad) {
|
||||
const texture = cesiumSampling(new Texture(), encoded);
|
||||
const image = new Image();
|
||||
image.crossOrigin = 'anonymous';
|
||||
const release = () => {
|
||||
image.onload = null;
|
||||
texture.image = null;
|
||||
texture.removeEventListener('dispose', release);
|
||||
};
|
||||
texture.addEventListener('dispose', release);
|
||||
image.onload = () => {
|
||||
image.onload = null;
|
||||
texture.image = image;
|
||||
texture.needsUpdate = true;
|
||||
onLoad();
|
||||
|
||||
@@ -23,6 +23,37 @@ const spriteOptions = normalizeMoverSetOptions({
|
||||
},
|
||||
});
|
||||
|
||||
test('disposing a sprite atlas drops decoded images and detaches pending load callbacks', (t) => {
|
||||
const previous = globalThis.Image;
|
||||
let image;
|
||||
globalThis.Image = class {
|
||||
constructor() { image = this; }
|
||||
};
|
||||
t.after(() => {
|
||||
if (previous) globalThis.Image = previous;
|
||||
else delete globalThis.Image;
|
||||
});
|
||||
const options = normalizeMoverSetOptions({
|
||||
...spriteOptions, sprite: {
|
||||
sizePx: 24, atlas: { url: '/bracket.svg', cells: { a: [0, 0, 1, 1] } },
|
||||
},
|
||||
});
|
||||
for (const loaded of [false, true]) {
|
||||
let frames = 0;
|
||||
const mover = createMoverMesh(options, createMoverStore(options), {
|
||||
onTextureLoad: () => frames++,
|
||||
});
|
||||
if (loaded) {
|
||||
image.onload();
|
||||
assert.equal(mover.mesh.material.map.image, image);
|
||||
}
|
||||
mover.dispose();
|
||||
assert.equal(image.onload, null);
|
||||
assert.equal(mover.mesh.material.map.image, null);
|
||||
assert.equal(frames, Number(loaded));
|
||||
}
|
||||
});
|
||||
|
||||
const basicShader = () => ({
|
||||
uniforms: UniformsUtils.clone(ShaderLib.basic.uniforms),
|
||||
vertexShader: ShaderLib.basic.vertexShader,
|
||||
|
||||
@@ -43,6 +43,17 @@ class GevOverlayEffectDesc extends EffectDesc {
|
||||
);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
// Navara removes the pass from its composer; our pass owns its GPU target
|
||||
// and context event handlers until it is explicitly disposed.
|
||||
const pass = this.raw?.rawPass;
|
||||
try {
|
||||
super.onDestroy();
|
||||
} finally {
|
||||
pass?.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Each drawn frame: the scene depth the overlays test against, then each
|
||||
// overlay's own per-frame work (pixel footprint, origin, viewport).
|
||||
update(time) {
|
||||
|
||||
Reference in new issue
Block a user