{"record":{"id":"af2f6de525bc2955","repo":"BabylonJS/Babylon.js","slug":"matrix-is-not-invertible","errorCode":null,"errorMessage":"Matrix is not invertible","messagePattern":"Matrix is not invertible","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/CustomTypes/flowGraphMatrix.ts","lineNumber":299,"sourceCode":"\n    public subtract(other: FlowGraphMatrix2D): FlowGraphMatrix2D {\n        return this.subtractToRef(other, new FlowGraphMatrix2D());\n    }\n\n    public transpose(): FlowGraphMatrix2D {\n        const m = this._m;\n        return new FlowGraphMatrix2D([m[0], m[2], m[1], m[3]]);\n    }\n\n    public determinant(): number {\n        const m = this._m;\n        return m[0] * m[3] - m[1] * m[2];\n    }\n\n    public inverse(): FlowGraphMatrix2D {\n        const det = this.determinant();\n        if (det === 0) {\n            throw new Error(\"Matrix is not invertible\");\n        }\n        const m = this._m;\n        const invDet = 1 / det;\n        return new FlowGraphMatrix2D([m[3] * invDet, -m[1] * invDet, -m[2] * invDet, m[0] * invDet]);\n    }\n\n    public equals(other: IFlowGraphMatrix<Vector2>, epsilon: number = 0): boolean {\n        const m = this._m;\n        const o = other.m;\n        if (epsilon === 0) {\n            return m[0] === o[0] && m[1] === o[1] && m[2] === o[2] && m[3] === o[3];\n        }\n        return Math.abs(m[0] - o[0]) < epsilon && Math.abs(m[1] - o[1]) < epsilon && Math.abs(m[2] - o[2]) < epsilon && Math.abs(m[3] - o[3]) < epsilon;\n    }\n\n    public getClassName(): string {\n        return \"FlowGraphMatrix2D\";\n    }","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/CustomTypes/flowGraphMatrix.ts#L281-L317","documentation":"FlowGraphMatrix2D.inverse() computes the 2x2 determinant and refuses to invert a singular matrix (det === 0) since the inverse would divide by zero. The matrix is degenerate — it collapses 2D space onto a line or point.","triggerScenarios":"Calling inverse() on a matrix whose determinant is exactly 0, e.g. one built from scale (0,0), collinear basis vectors, or accumulated degenerate transforms.","commonSituations":"Animated scale interpolating through 0; matrices constructed from empty/degenerate input data; default/uninitialized matrices filled with zeros; computing UV/2D transforms from geometry with zero area.","solutions":["Check the determinant before inverting and handle the singular case (identity fallback or error path)","Fix the upstream transform data producing the zero determinant (non-zero scale, non-collinear basis)","If a near-singular matrix is expected, use a regularized/pseudo-inverse approach instead of exact inverse"],"exampleFix":"// before\nconst inv = m.inverse(); // throws when det===0\n// after\nconst inv = m.determinant() !== 0 ? m.inverse() : FlowGraphMatrix2D.Identity();","handlingStrategy":"validation","validationCode":"if (m.determinant() === 0) { /* use identity or abort */ }\nconst inv = m.determinant() !== 0 ? m.inverse() : FlowGraphMatrix2D.Identity();","typeGuard":"const isInvertible2D = (m: FlowGraphMatrix2D): boolean => m.determinant() !== 0;","tryCatchPattern":"try { inv = m.inverse(); } catch (e) { if (e.message === 'Matrix is not invertible') { inv = FlowGraphMatrix2D.Identity(); } else throw e; }","preventionTips":["Clamp animated scale values away from zero","Initialize matrices with valid values before use","Check determinant before every inverse call in generic transform pipelines"],"tags":["flow-graph","matrix","math"],"backgroundTag":"singular-matrix","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}