{"record":{"id":"4e3b330977437ada","repo":"MonoGame/MonoGame","slug":"farplanedistance-0","errorCode":null,"errorMessage":"farPlaneDistance <= 0","messagePattern":"farPlaneDistance <= 0","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework/Matrix.cs","lineNumber":923,"sourceCode":"        }\r\n\r\n        /// <summary>\r\n        /// Creates a new projection <see cref=\"Matrix\"/> for perspective view.\r\n        /// </summary>\r\n        /// <param name=\"width\">Width of the viewing volume.</param>\r\n        /// <param name=\"height\">Height of the viewing volume.</param>\r\n        /// <param name=\"nearPlaneDistance\">Distance to the near plane.</param>\r\n        /// <param name=\"farPlaneDistance\">Distance to the far plane, or <see cref=\"float.PositiveInfinity\"/>.</param>\r\n        /// <param name=\"result\">The new projection <see cref=\"Matrix\"/> for perspective view as an output parameter.</param>\r\n        public static void CreatePerspective(float width, float height, float nearPlaneDistance, float farPlaneDistance, out Matrix result)\r\n        {\r\n            if (nearPlaneDistance <= 0f)\r\n\t\t    {\r\n\t\t        throw new ArgumentException(\"nearPlaneDistance <= 0\");\r\n\t\t    }\r\n\t\t    if (farPlaneDistance <= 0f)\r\n\t\t    {\r\n\t\t        throw new ArgumentException(\"farPlaneDistance <= 0\");\r\n\t\t    }\r\n\t\t    if (nearPlaneDistance >= farPlaneDistance)\r\n\t\t    {\r\n\t\t        throw new ArgumentException(\"nearPlaneDistance >= farPlaneDistance\");\r\n\t\t    }\r\n\r\n            var negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance);\r\n\r\n            result.M11 = (2.0f * nearPlaneDistance) / width;\r\n            result.M12 = result.M13 = result.M14 = 0.0f;\r\n            result.M22 = (2.0f * nearPlaneDistance) / height;\r\n            result.M21 = result.M23 = result.M24 = 0.0f;            \r\n            result.M33 = negFarRange;\r\n            result.M31 = result.M32 = 0.0f;\r\n            result.M34 = -1.0f;\r\n            result.M41 = result.M42 = result.M44 = 0.0f;\r\n            result.M43 = nearPlaneDistance * negFarRange;\r\n        }\r","sourceCodeStart":905,"sourceCodeEnd":941,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework/Matrix.cs#L905-L941","documentation":"Thrown as ArgumentException by Matrix.CreatePerspective when farPlaneDistance is less than or equal to zero. The far plane must be positive (float.PositiveInfinity is explicitly allowed by the API).","triggerScenarios":"Passing farPlaneDistance = 0, a negative value, or an unset value to CreatePerspective.","commonSituations":"Defaulting far to 0; computing far as a difference that goes negative; deserialized camera config with missing far value.","solutions":["Set farPlaneDistance to a large positive value (e.g. 1000f) or float.PositiveInfinity.","Validate and clamp far to a positive value before calling.","Ensure config deserialization does not leave far at 0."],"exampleFix":"// before\nMatrix.CreatePerspective(w, h, 0.1f, 0f, out proj); // far=0\n\n// after\nMatrix.CreatePerspective(w, h, 0.1f, 1000f, out proj);","handlingStrategy":"validation","validationCode":"float far = farPlaneDistance <= 0f ? 1000f : farPlaneDistance;\nMatrix.CreatePerspective(w, h, nearPlaneDistance, far, out proj);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a large positive far or float.PositiveInfinity.","Validate far is positive after deserialization.","Clamp computed far values to a positive minimum."],"tags":["monogame","math","matrix","camera","argument"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}