mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Cesium draw: a material or quad drawing a blob keeps it alive
An image material loads its image on its first draw, and an atlas slot given a new image no longer holds the old blob, so a hidden fill, pattern or quad built from a slot could lose its blob to collection, its URL revoked, before it was ever drawn. Each material built from a blob (shape and ground image fills, line patterns) and each quad now holds the blob it draws while it lives.
This commit is contained in:
1 parent
151230f5fa
commit
2a1e2d9c0b
4 files changed
+123
-10
No files matched your search
@@ -1253,6 +1253,8 @@ export function createCesiumDraw({
|
||||
// when its icon is drawn, and registering an atlas again swaps the images
|
||||
// of the icons that drew from it.
|
||||
const atlases = new Map();
|
||||
/** The blob each material or quad draws, held while it lives (`holdImage`). */
|
||||
const heldBlobs = new WeakMap();
|
||||
|
||||
/**
|
||||
* An icon's image: an atlas slot read through its atlas, or undefined
|
||||
@@ -1270,11 +1272,27 @@ export function createCesiumDraw({
|
||||
* registered is refused, as an image it cannot read).
|
||||
*/
|
||||
function imageAt(image) {
|
||||
return toImage(
|
||||
typeof image?.atlas === 'string'
|
||||
? (atlases.get(image.atlas)?.[image.slot] ?? image)
|
||||
: image,
|
||||
);
|
||||
return toImage(slotImage(image));
|
||||
}
|
||||
|
||||
/** An atlas slot as the image it holds now; any other image as it is. */
|
||||
function slotImage(image) {
|
||||
return typeof image?.atlas === 'string'
|
||||
? (atlases.get(image.atlas)?.[image.slot] ?? image)
|
||||
: image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep the blob behind `image` (itself, or the atlas slot's now) alive
|
||||
* while `holder` (a material, a quad) lives. A material loads its image
|
||||
* from the blob's URL on its first draw, which may come long after it was
|
||||
* built (hidden till then), and a blob's URL is revoked once the blob is
|
||||
* collected: an atlas slot given a new image no longer holds the old one.
|
||||
*/
|
||||
function holdImage(holder, image) {
|
||||
const blob = slotImage(image)?.blob;
|
||||
if (holder && blob) heldBlobs.set(holder, blob);
|
||||
return holder;
|
||||
}
|
||||
|
||||
function buildIcons(record) {
|
||||
@@ -2117,6 +2135,7 @@ export function createCesiumDraw({
|
||||
Object.assign(drawn.uniforms, fabric.uniforms);
|
||||
const flow = flowOf(material, style);
|
||||
if (flow) record.flowMaterials.push(flow);
|
||||
if (style.kind === 'pattern') holdImage(material, style.image);
|
||||
return material;
|
||||
}
|
||||
|
||||
@@ -4244,7 +4263,10 @@ export function createCesiumDraw({
|
||||
: UnpickableGroundPrimitive;
|
||||
const grounds = batches.map((batch) => {
|
||||
const material = batch.imageFill
|
||||
? imageMaterial(batch.image, batch.imageFill.repeat)
|
||||
? holdImage(
|
||||
imageMaterial(batch.image, batch.imageFill.repeat),
|
||||
batch.imageFill.image,
|
||||
)
|
||||
: null;
|
||||
const ground = new Ground({
|
||||
geometryInstances: batch.instances,
|
||||
@@ -4948,8 +4970,11 @@ export function createCesiumDraw({
|
||||
// `lit`: shaded by Cesium's light, or flat; by default solids are lit.
|
||||
const lit = item.lit ?? solid;
|
||||
if (imageFill && !item.outlineOnly) {
|
||||
const material = ownMaterial(
|
||||
imageMaterial(imageAt(imageFill.image), imageFill.repeat),
|
||||
const material = holdImage(
|
||||
ownMaterial(
|
||||
imageMaterial(imageAt(imageFill.image), imageFill.repeat),
|
||||
),
|
||||
imageFill.image,
|
||||
);
|
||||
// Its image is changed in place (`writeImage`); it never recolours.
|
||||
part.image = { material, texture: null };
|
||||
@@ -5073,6 +5098,7 @@ export function createCesiumDraw({
|
||||
const quadSets = createQuadSets({
|
||||
toColor,
|
||||
toImage: imageAt,
|
||||
holdImage,
|
||||
pickId,
|
||||
replaceHost,
|
||||
lineWidth,
|
||||
|
||||
Reference in new issue
Block a user