Destroy an image fill's texture its material never took

A material takes a texture, and destroys it later, only when it next
updates. A canvas fill replaced by one of another size twice before a
frame, or disposed before one, left the texture in between to no one.
Such a texture is now destroyed when it is replaced or its shapes go.
This commit is contained in:
Sameh Khamis committed 2026-11-10 09:46:03 -08:00
1 parent f834903950
commit c56ff090e6
1 file changed
+18
+18
View File
@@ -3710,10 +3710,24 @@ export function createCesiumDraw({
texture.copyFrom({ source: canvas });
return;
}
dropPendingTexture(image);
image.texture = new Cesium.Texture({ context, source: canvas });
image.material.uniforms.image = image.texture;
}
/**
* Destroys an image fill's newest texture if its material has not taken
* it yet. A material takes a texture (and destroys it later) only when it
* next updates, so one replaced or disposed before then is no one's.
*/
function dropPendingTexture(image) {
const texture = image.texture;
if (!texture || texture.isDestroyed()) return;
if (image.material._textures?.image === texture) return;
texture.destroy();
image.texture = null;
}
/** An instance's colour, in a ready primitive. */
function colourOn(primitive, id, color) {
const attributes = primitive.getGeometryInstanceAttributes(id);
@@ -4009,10 +4023,13 @@ export function createCesiumDraw({
// Image fills' materials hold their textures, which primitives leave
// alone: the host destroys them as it goes.
const materials = [];
// Image fills, whose newest texture the material may not hold yet.
const images = [];
const ownMaterial = (material) => {
if (!materials.length) {
const destroyHost = host.destroy.bind(host);
host.destroy = () => {
for (const image of images.splice(0)) dropPendingTexture(image);
for (const owned of materials.splice(0))
if (!owned.isDestroyed()) owned.destroy();
return destroyHost();
@@ -4071,6 +4088,7 @@ export function createCesiumDraw({
);
// Its image is changed in place (`writeImage`); it never recolours.
part.image = { material, texture: null };
images.push(part.image);
part.translucent.fill = true;
part.fill = host.add(
new Cesium.Primitive({