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

  1. Audit custom nodes that add to stacks and ensure every branch pops the same stack.
  2. Do not reuse StackNode instances across builders; clone them.
  3. 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

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


AI-assisted analysis of mrdoob/three.js@da05705fa3 (2026-08-12). Data as JSON: /api/errors/0ce6c7f714db1300. Report an issue: GitHub.