3D engine that AI agents drive
Fix the animation loop hang: reuse held parts on re-render, time out each snippet (#986)
Nguyen Xuan Anf80988f09c1b
diff --git a/packages/three-compat/index.mjs b/packages/three-compat/index.mjsindex aa520ef0..0e339b85 100644--- a/packages/three-compat/index.mjs+++ b/packages/three-compat/index.mjs@@ -638,8 +638,14 @@ export function createThreeCompat(core) {ground: false, samples: this.antialias ? 4 : 1, pixelRatio: this.pixelRatio, environment,});this.structure = key;+ this.heldParts = parts;} else {- this.renderer67.updateParts(parts);+ // The renderer knows its parts by object identity, and collectScene makes new objects each call: carry the new pose onto the held ones.+ parts.forEach((part, index) => {+ this.heldParts[index].matrix = part.matrix;+ this.heldParts[index].material = part.material;+ });+ this.renderer67.updateParts(this.heldParts);}this.renderer67.resize();this.renderer67.render({ ...frame, environment });diff --git a/tests/three-compat.test.js b/tests/three-compat.test.jsindex 093d1408..70bfb5fe 100644--- a/tests/three-compat.test.js+++ b/tests/three-compat.test.js@@ -192,6 +192,21 @@ test('every 67js call named by an error exists', () => {const chromePath = process.env.CHROME_PATH ?? 'C:/Program Files/Google/Chrome/Application/chrome.exe';const renderEnabled = process.env.RENDER_TESTS === '1' && existsSync(chromePath);+const snippetTimeoutMilliseconds = 20000;++// A snippet that never reports a frame fails by name instead of holding the whole test until its own timeout.+async function drawWithin(page, name, milliseconds) {+ let timer;+ const timeout = new Promise((resolve, reject) => {+ timer = setTimeout(() => reject(new Error(`snippet "${name}" reported no frame within ${milliseconds} ms`)), milliseconds);+ });+ try {+ return await Promise.race([page.evaluate(snippetName => window.drawSnippet(snippetName), name), timeout]);+ } finally {+ clearTimeout(timer);+ }+}+test('each three.js-style snippet draws a frame through the addon', { skip: !renderEnabled, timeout: 300000 }, async () => {setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);const { chromium } = await import('playwright');@@ -210,7 +225,7 @@ test('each three.js-style snippet draws a frame through the addon', { skip: !renawait page.waitForFunction(() => window.drawSnippet, null, { timeout: 60000 });const hashes = new Set();for (const snippet of snippets) {- const result = await page.evaluate(name => window.drawSnippet(name), snippet.name);+ const result = await drawWithin(page, snippet.name, snippetTimeoutMilliseconds);assert.ok(result.frames >= 1, `${snippet.name} drew a frame`);assert.ok(result.distinctColors >= 12, `${snippet.name} is not a blank frame (${result.distinctColors} colours)`);assert.ok(!hashes.has(result.hash), `${snippet.name} differs from every other snippet`);