{"record":{"id":"627cd08286211e6d","repo":"BabylonJS/Babylon.js","slug":"unsupported-stencil-depthfail-mode-depthfail","errorCode":null,"errorMessage":"Unsupported stencil depthFail mode: ${depthFail}.","messagePattern":"Unsupported stencil depthFail mode: (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Engines/Native/nativeHelpers.ts","lineNumber":276,"sourceCode":"    switch (depthFail) {\r\n        case Constants.KEEP:\r\n            return _native.Engine.STENCIL_OP_FAIL_Z_KEEP;\r\n        case Constants.ZERO:\r\n            return _native.Engine.STENCIL_OP_FAIL_Z_ZERO;\r\n        case Constants.REPLACE:\r\n            return _native.Engine.STENCIL_OP_FAIL_Z_REPLACE;\r\n        case Constants.INCR:\r\n            return _native.Engine.STENCIL_OP_FAIL_Z_INCR;\r\n        case Constants.DECR:\r\n            return _native.Engine.STENCIL_OP_FAIL_Z_DECR;\r\n        case Constants.INVERT:\r\n            return _native.Engine.STENCIL_OP_FAIL_Z_INVERT;\r\n        case Constants.INCR_WRAP:\r\n            return _native.Engine.STENCIL_OP_FAIL_Z_INCRSAT;\r\n        case Constants.DECR_WRAP:\r\n            return _native.Engine.STENCIL_OP_FAIL_Z_DECRSAT;\r\n        default:\r\n            throw new Error(`Unsupported stencil depthFail mode: ${depthFail}.`);\r\n    }\r\n}\r\n\r\nexport function getNativeStencilDepthPass(opPass: number): number {\r\n    switch (opPass) {\r\n        case Constants.KEEP:\r\n            return _native.Engine.STENCIL_OP_PASS_Z_KEEP;\r\n        case Constants.ZERO:\r\n            return _native.Engine.STENCIL_OP_PASS_Z_ZERO;\r\n        case Constants.REPLACE:\r\n            return _native.Engine.STENCIL_OP_PASS_Z_REPLACE;\r\n        case Constants.INCR:\r\n            return _native.Engine.STENCIL_OP_PASS_Z_INCR;\r\n        case Constants.DECR:\r\n            return _native.Engine.STENCIL_OP_PASS_Z_DECR;\r\n        case Constants.INVERT:\r\n            return _native.Engine.STENCIL_OP_PASS_Z_INVERT;\r\n        case Constants.INCR_WRAP:\r","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Engines/Native/nativeHelpers.ts#L258-L294","documentation":"getNativeStencilDepthFail maps the stencil depth-fail op constant to the Babylon Native STENCIL_OP_FAIL_Z_* enum. Any depthFail value passed via applyStencil that doesn't match a known Constants stencil op falls to the default case and throws. Same guard pattern as the OpFail variant, for the depth-fail slot.","triggerScenarios":"Calling engine.applyStencil(faceMode, opFail, depthFail) with a depthFail value not among Constants.KEEP/ZERO/REPLACE/INCR/DECR/INVERT/INCR_WRAP/DECR_WRAP, such as an arbitrary integer or undefined.","commonSituations":"Using raw WebGL GLenum values instead of Babylon Constants; passing swapped arguments (op in the depthFail position); older code using constants removed in newer versions.","solutions":["Pass a valid Constants stencil op for depthFail (e.g. Constants.KEEP, Constants.DECR_WRAP).","Verify argument order in applyStencil so the depth-fail op lands in the third parameter.","Confirm the value is a number defined on Constants before calling."],"exampleFix":"// before\nengine.applyStencil(true, Constants.KEEP, gl.GL_INCR, Constants.KEEP);\n// after\nengine.applyStencil(true, Constants.KEEP, Constants.INCR, Constants.KEEP);","handlingStrategy":"validation","validationCode":"const OPS = [BABYLON.Constants.KEEP, BABYLON.Constants.ZERO, BABYLON.Constants.REPLACE, BABYLON.Constants.INCR, BABYLON.Constants.DECR, BABYLON.Constants.INVERT, BABYLON.Constants.INCR_WRAP, BABYLON.Constants.DECR_WRAP];\nif (!OPS.includes(depthFail)) throw new RangeError(`depthFail must be a Constants stencil op, got ${depthFail}`);","typeGuard":"function isStencilOp(v: unknown): v is number {\n  const C = BABYLON.Constants;\n  return typeof v === 'number' && [C.KEEP, C.ZERO, C.REPLACE, C.INCR, C.DECR, C.INVERT, C.INCR_WRAP, C.DECR_WRAP].includes(v);\n}","tryCatchPattern":"try {\n  engine.applyStencil(face, opFail, depthFail, opPass);\n} catch (e) {\n  if (String(e.message).includes('depthFail mode')) {\n    console.warn('Bad depthFail, using KEEP', depthFail);\n    engine.applyStencil(face, opFail, BABYLON.Constants.KEEP, opPass);\n  } else throw e;\n}","preventionTips":["Check applyStencil argument order when migrating raw-WebGL stencil code.","Validate all stencil ops against Constants before configuring the engine.","Avoid hardcoded hex GL enums from old renderers."],"tags":["babylonjs","stencil","native-engine","invalid-enum"],"backgroundTag":"unsupported-enum-value","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}