mrdoob/three.js · error
THREE.NodeBuilder: Invalid active stack removal.
Error message
THREE.NodeBuilder: Invalid active stack removal.
What it means
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.
Source
Thrown at src/nodes/core/NodeBuilder.js:1838
this.activeStacks.push( stack );
}
/**
* Removes the active stack from the internal stack.
*
* @param {StackNode} stack - The stack node to remove.
*/
removeActiveStack( stack ) {
if ( this.activeStacks[ this.activeStacks.length - 1 ] === stack ) {
this.activeStacks.pop();
} else {
throw new Error( 'THREE.NodeBuilder: Invalid active stack removal.' );
}
}
/**
* Returns the active stack.
*
* @return {StackNode} The active stack.
*/
getActiveStack() {
return this.activeStacks[ this.activeStacks.length - 1 ];
}
/**
* Returns the base stack.View on GitHub (pinned to da05705fa3)
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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
renderer.compileAsync( scene, camera );
} catch ( e ) {
if ( /Invalid active stack removal/.test( e.message ) ) {
console.error( 'Unbalanced StackNode usage — audit custom stack-manipulating nodes', e );
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Custom TSL nodes using `StackNode` or `addToStack`; modifying a node graph mid-build; sharing stack nodes between materials; regression after a Three.js upgrade.
Related errors
- THREE.NodeBuilder: Invalid node chaining!
- THREE.NodeBuilder: Type '${type}' not found in generate cons
- THREE.NodeBuilder: Uniform "${ type }" not implemented.
AI-assisted analysis of mrdoob/three.js@da05705fa3 (2026-08-12).
Data as JSON: /api/errors/0ce6c7f714db1300.
Report an issue: GitHub.