Skip to content

3D engine that AI agents drive

Refuse a spray index entry that is not two whole numbers (#2627)

abu-tahir-0d51762dfa8ee
diff --git a/changes/2627.md b/changes/2627.md
new file mode 100644
index 00000000..d77e865e
--- /dev/null
+++ b/changes/2627.md
@@ -0,0 +1 @@
+- A Spume spray index entry that is not two whole numbers from 0 is refused by frame, instead of building phantom droplets (#2627)
diff --git a/src/spume.js b/src/spume.js
index a82ba6b2..0eceded3 100644
--- a/src/spume.js
+++ b/src/spume.js
@@ -135,6 +135,11 @@ function validateMeta(meta) {
if (typeof meta.frameFile !== 'string' || !meta.frameFile.includes('%04d')) throw new TypeError('Spume meta.frameFile must contain %04d.');
const sprayIndex = meta.spray?.index;
if (meta.spray && (!Array.isArray(sprayIndex) || sprayIndex.length !== meta.frameCount)) throw new RangeError('Spume spray index must list every frame.');
+ sprayIndex?.forEach((entry, frame) => {
+ if (!Array.isArray(entry) || entry.length !== 2 || !entry.every(value => Number.isInteger(value) && value >= 0)) {
+ throw new RangeError(`Spume spray.index[${frame}] must be [first, count] as two whole numbers from 0.`);
+ }
+ });
if (meta.spray && meta.spray.floatsPerPoint !== SPRAY_FLOATS_PER_POINT) throw new RangeError('Spume spray must store six floats per point.');
}
diff --git a/tests/spume.test.js b/tests/spume.test.js
index 18ecb902..72bed5bf 100644
--- a/tests/spume.test.js
+++ b/tests/spume.test.js
@@ -156,6 +156,22 @@ test('spray options that would build no or broken droplets are refused by name',
}
});
+test('a spray index entry that is not two whole numbers from 0 is refused by frame (#2627)', async () => {
+ for (const [frame, entry] of [[0, ['a', 2]], [1, [-1, 2]], [1, [0, 1.5]], [0, [0]]]) {
+ const read = syntheticCache();
+ const source = async name => {
+ if (name !== 'meta.json') return read(name);
+ const meta = JSON.parse(new TextDecoder().decode(await read(name)));
+ meta.spray.index[frame] = entry;
+ return new TextEncoder().encode(JSON.stringify(meta)).buffer;
+ };
+ await assert.rejects(loadSpumeCache(source), new RegExp(`spray\\.index\\[${frame}\\]`), `entry ${JSON.stringify(entry)}`);
+ }
+ const cache = await loadSpumeCache(syntheticCache());
+ assert.equal(cache.spray.index.length, 2, 'a valid cache still loads');
+ assert.equal(buildSprayGeometry(cache, 1).indices.length, 2 * 24, 'and builds the same droplets');
+});
+
function cacheWithSpray(points) {
const read = syntheticCache();
const encode = value => (Number.isFinite(value) ? float16Bits(value) : value === Infinity ? 0x7c00 : 0x7e00);