{"record":{"id":"0f0b4dc13a9a280e","repo":"CoplayDev/unity-mcp","slug":"width-should-be-larger-than-0","errorCode":null,"errorMessage":"Width should be larger than 0","messagePattern":"Width should be larger than 0","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/Screenshotters/SceneScreenshotterBase.cs","lineNumber":39,"sourceCode":"\r\n        private Camera GetCamera()\r\n        {\r\n            if (_camera == null)\r\n            {\r\n#if UNITY_2022_3_OR_NEWER\r\n                _camera = GameObject.FindFirstObjectByType<Camera>(FindObjectsInactive.Include);\r\n#else\r\n                _camera = GameObject.FindObjectOfType<Camera>();\r\n#endif\r\n            }\r\n\r\n            return _camera;\r\n        }\r\n\r\n        public virtual void ValidateSettings()\r\n        {\r\n            if (Settings.Width <= 0)\r\n                throw new ArgumentException(\"Width should be larger than 0\");\r\n\r\n            if (Settings.Height <= 0)\r\n                throw new ArgumentException(\"Height should be larger than 0\");\r\n\r\n            if (Settings.Depth <= 0)\r\n                throw new ArgumentException(\"Depth should be larger than 0\");\r\n\r\n            if (Settings.NativeWidth <= 0)\r\n                throw new ArgumentException(\"Native width should be larger than 0\");\r\n\r\n            if (Settings.NativeHeight <= 0)\r\n                throw new ArgumentException(\"Native height should be larger than 0\");\r\n        }\r\n\r\n        public abstract void PositionCamera(GameObject target);\r\n\r\n        public string Screenshot(string outputPath)\r\n        {\r","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/Screenshotters/SceneScreenshotterBase.cs#L21-L57","documentation":"Thrown by SceneScreenshotterBase.ValidateSettings when Settings.Width is zero or negative. Width is used to dimension the output screenshot texture. The validation runs synchronously inside Screenshot() before any camera rendering.","triggerScenarios":"Calling Screenshot(outputPath) or ValidateSettings() on a SceneScreenshotterBase subclass with Settings.Width <= 0.","commonSituations":"Screenshot settings deserialized from config with a missing/default width field; UI slider left at 0; settings object constructed without setting Width after a reset.","solutions":["Set Settings.Width to a positive integer (e.g., 1024 or 1920) before calling Screenshot.","If settings come from a serialized source, apply sensible defaults after deserialization.","Add a UI-side clamp so width cannot be saved as zero."],"exampleFix":"// before\nvar settings = new SceneScreenshotterSettings { Width = 0, Height = 1080, ... };\nscreenshotter.Screenshot(outputPath);\n\n// after\nvar settings = new SceneScreenshotterSettings { Width = 1920, Height = 1080, ... };\nscreenshotter.Screenshot(outputPath);","handlingStrategy":"validation","validationCode":"if (settings.Width <= 0)\n    settings.Width = 1920; // apply default\n// or validate before calling Screenshot:\nif (settings.Width <= 0)\n    throw new InvalidOperationException(\"Screenshot Width must be set to a positive value.\");","typeGuard":"static bool IsValidScreenshotDimensions(SceneScreenshotterSettings s)\n    => s.Width > 0 && s.Height > 0 && s.Depth > 0 && s.NativeWidth > 0 && s.NativeHeight > 0;","tryCatchPattern":"try\n{\n    screenshotter.Screenshot(outputPath);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Width should be larger than 0\"))\n{\n    settings.Width = 1920;\n    screenshotter.Screenshot(outputPath); // retry with default\n}","preventionTips":["Initialize all screenshot dimension fields in a single factory method.","Clamp UI inputs to minimum 1 for all dimension fields.","Apply post-deserialization defaults for any zero-valued numeric fields."],"tags":["unity","asset-store-tools","preview","validation","screenshot"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}