{"record":{"id":"0ce6c7f714db1300","repo":"mrdoob/three.js","slug":"three-nodebuilder-invalid-active-stack-removal","errorCode":null,"errorMessage":"THREE.NodeBuilder: Invalid active stack removal.","messagePattern":"THREE\\.NodeBuilder: Invalid active stack removal\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/nodes/core/NodeBuilder.js","lineNumber":1838,"sourceCode":"\n\t\tthis.activeStacks.push( stack );\n\n\t}\n\n\t/**\n\t * Removes the active stack from the internal stack.\n\t *\n\t * @param {StackNode} stack - The stack node to remove.\n\t */\n\tremoveActiveStack( stack ) {\n\n\t\tif ( this.activeStacks[ this.activeStacks.length - 1 ] === stack ) {\n\n\t\t\tthis.activeStacks.pop();\n\n\t\t} else {\n\n\t\t\tthrow new Error( 'THREE.NodeBuilder: Invalid active stack removal.' );\n\n\t\t}\n\n\t}\n\n\t/**\n\t * Returns the active stack.\n\t *\n\t * @return {StackNode} The active stack.\n\t */\n\tgetActiveStack() {\n\n\t\treturn this.activeStacks[ this.activeStacks.length - 1 ];\n\n\t}\n\n\t/**\n\t * Returns the base stack.","sourceCodeStart":1820,"sourceCodeEnd":1856,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/nodes/core/NodeBuilder.js#L1820-L1856","documentation":"An internal NodeBuilder invariant: `removeActiveStack(stack)` only pops when the top of `activeStacks` is the same stack node. Like error 42, it signals unbalanced push/pop of stack nodes during traversal and is almost always a library or custom-Node bug rather than user config.","triggerScenarios":"A custom node that manipulates the active stack (via builder flow methods) without symmetric enter/exit; a StackNode reused across concurrent builds; an exception inside a stack scope that skips the matching pop; conditional stack usage inside Fn that branches asymmetrically.","commonSituations":"Custom TSL nodes using `StackNode` or `addToStack`; modifying a node graph mid-build; sharing stack nodes between materials; regression after a Three.js upgrade.","solutions":["Audit custom nodes that add to stacks and ensure every branch pops the same stack.","Do not reuse StackNode instances across builders; clone them.","If reproducible with built-in nodes only, report as a library regression."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  renderer.compileAsync( scene, camera );\n} catch ( e ) {\n  if ( /Invalid active stack removal/.test( e.message ) ) {\n    console.error( 'Unbalanced StackNode usage — audit custom stack-manipulating nodes', e );\n  } else throw e;\n}","preventionTips":["In custom nodes that touch the active stack, balance every push with a pop on all branches.","Do not reuse StackNode instances across materials/builders.","Avoid mutating the node graph during a build."],"tags":["node-builder","stack-node","internal-invariant"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}