{"record":{"id":"3a5dca5bf956623d","repo":"BabylonJS/Babylon.js","slug":"block-is-not-part-of-this-smart-filter","errorCode":null,"errorMessage":"\"Block is not part of this smart filter\"","messagePattern":"\"Block is not part of this smart filter\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/smartFilters/src/smartFilter.ts","lineNumber":126,"sourceCode":"    }\r\n\r\n    /**\r\n     * @returns The current class name of the smart filter.\r\n     */\r\n    public getClassName(): string {\r\n        return \"SmartFilter\";\r\n    }\r\n\r\n    /**\r\n     * Registers a block to be part of this smart filter.\r\n     * @param block - The block to register on the smart filter\r\n     * @throws if the block is already registered on another smart filter\r\n     * @remarks This function will not register the block if it is already registered on the smart filter.\r\n     */\r\n    public registerBlock(block: BaseBlock): void {\r\n        // It is impossible to attach a block from another filter\r\n        if (block.smartFilter !== this) {\r\n            throw new Error(\"Block is not part of this smart filter\");\r\n        }\r\n\r\n        // No need to attach a block several times\r\n        if (this._attachedBlocks.indexOf(block) !== -1) {\r\n            return;\r\n        }\r\n\r\n        // Add the block to the list of attached blocks\r\n        this._attachedBlocks.push(block);\r\n    }\r\n\r\n    /**\r\n     * Removes the block from the smart filter.\r\n     * @param block - The block to remove from the smart filter\r\n     * @remarks This function will disconnect the block on removal.\r\n     * This Output block cannot be removed.\r\n     */\r\n    public removeBlock(block: BaseBlock): void {\r","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/smartFilters/src/smartFilter.ts#L108-L144","documentation":"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.","triggerScenarios":"Calling smartFilter.registerBlock(block) on a block that was already constructed with or attached to another SmartFilter instance.","commonSituations":"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.","solutions":["Create a new instance of the block for each SmartFilter instead of reusing one.","Detach/remove the block from the other smart filter before registering it here.","Check block.smartFilter before calling registerBlock to detect accidental sharing.","Fix caching so blocks are per-filter rather than shared module singletons."],"exampleFix":"// before\nfilterA.registerBlock(sharedBlock);\nfilterB.registerBlock(sharedBlock); // throws\n// after\nconst blockA = new BlurBlock();\nfilterA.registerBlock(blockA);\nconst blockB = new BlurBlock();\nfilterB.registerBlock(blockB);","handlingStrategy":"validation","validationCode":"if (block.smartFilter && block.smartFilter !== targetFilter) { throw new Error(`Block ${block.name} already belongs to another smart filter`); }\ntargetFilter.registerBlock(block);","typeGuard":"const isUnattached = (b: BaseBlock, f: SmartFilter): b is BaseBlock => b.smartFilter === f;","tryCatchPattern":"try { filter.registerBlock(block); } catch (e) { if (e.message.includes('not part of this smart filter')) { createNewBlockForFilter(); } else { throw e; } }","preventionTips":["Never share block instances between SmartFilters — instantiate per filter.","Avoid module-level block singletons.","Check block.smartFilter before re-registering."],"tags":["smart-filters","block-registration","shared-state"],"backgroundTag":"block-already-attached","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}