BabylonJS/Babylon.js · error · Error

"Block is not part of this smart filter"

Error message

"Block is not part of this smart filter"

What it means

registerBlock() is called during a smart filter's construction to attach its blocks. This error means a BaseBlock being registered currently belongs to a different SmartFilter instance (block.smartFilter !== this). The library forbids sharing a block instance between filters because a block can only be wired into one filter graph.

Source

Thrown at packages/dev/smartFilters/src/smartFilter.ts:126

    }

    /**
     * @returns The current class name of the smart filter.
     */
    public getClassName(): string {
        return "SmartFilter";
    }

    /**
     * Registers a block to be part of this smart filter.
     * @param block - The block to register on the smart filter
     * @throws if the block is already registered on another smart filter
     * @remarks This function will not register the block if it is already registered on the smart filter.
     */
    public registerBlock(block: BaseBlock): void {
        // It is impossible to attach a block from another filter
        if (block.smartFilter !== this) {
            throw new Error("Block is not part of this smart filter");
        }

        // No need to attach a block several times
        if (this._attachedBlocks.indexOf(block) !== -1) {
            return;
        }

        // Add the block to the list of attached blocks
        this._attachedBlocks.push(block);
    }

    /**
     * Removes the block from the smart filter.
     * @param block - The block to remove from the smart filter
     * @remarks This function will disconnect the block on removal.
     * This Output block cannot be removed.
     */
    public removeBlock(block: BaseBlock): void {

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Create a new instance of the block for each SmartFilter instead of reusing one.
  2. Detach/remove the block from the other smart filter before registering it here.
  3. Check block.smartFilter before calling registerBlock to detect accidental sharing.
  4. Fix caching so blocks are per-filter rather than shared module singletons.

Example fix

// before
filterA.registerBlock(sharedBlock);
filterB.registerBlock(sharedBlock); // throws
// after
const blockA = new BlurBlock();
filterA.registerBlock(blockA);
const blockB = new BlurBlock();
filterB.registerBlock(blockB);
Defensive patterns

Strategy: validation

Validate before calling

if (block.smartFilter && block.smartFilter !== targetFilter) { throw new Error(`Block ${block.name} already belongs to another smart filter`); }
targetFilter.registerBlock(block);

Type guard

const isUnattached = (b: BaseBlock, f: SmartFilter): b is BaseBlock => b.smartFilter === f;

Try / catch

try { filter.registerBlock(block); } catch (e) { if (e.message.includes('not part of this smart filter')) { createNewBlockForFilter(); } else { throw e; } }

Prevention

When it happens

Trigger: Calling smartFilter.registerBlock(block) on a block that was already constructed with or attached to another SmartFilter instance.

Common situations: Reusing a block object across two filters; copying a block reference from a previously loaded filter; caching blocks in a module-level variable and attaching them to a newly created filter.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/3a5dca5bf956623d. Report an issue: GitHub.