{"record":{"id":"89a8d5669325ab8a","repo":"CoplayDev/unity-mcp","slug":"width-must-be-larger-than-0","errorCode":null,"errorMessage":"Width must be larger than 0","messagePattern":"Width must 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/TypeGenerators/AudioTypePreviewGenerator.cs","lineNumber":30,"sourceCode":"{\r\n    internal class AudioTypePreviewGenerator : TypePreviewGeneratorBase\r\n    {\r\n        private AudioTypeGeneratorSettings _settings;\r\n        private Texture2D _texture;\r\n\r\n        public override event Action<int, int> OnAssetProcessed;\r\n\r\n        public AudioTypePreviewGenerator(AudioTypeGeneratorSettings settings) : base(settings)\r\n        {\r\n            _settings = settings;\r\n        }\r\n\r\n        public override void ValidateSettings()\r\n        {\r\n            base.ValidateSettings();\r\n\r\n            if (_settings.Width <= 0)\r\n                throw new ArgumentException(\"Width must be larger than 0\");\r\n\r\n            if (_settings.Height <= 0)\r\n                throw new ArgumentException(\"Height must be larger than 0\");\r\n        }\r\n\r\n        protected override IEnumerable<UnityEngine.Object> CollectAssets()\r\n        {\r\n            var assets = new List<UnityEngine.Object>();\r\n            var materialGuids = AssetDatabase.FindAssets(\"t:audioclip\", Settings.InputPaths);\r\n            foreach (var guid in materialGuids)\r\n            {\r\n                var audioClip = AssetDatabase.LoadAssetAtPath<AudioClip>(AssetDatabase.GUIDToAssetPath(guid));\r\n\r\n                // Skip nested audio clips\r\n                if (!AssetDatabase.IsMainAsset(audioClip))\r\n                    continue;\r\n\r\n                // Skip materials with an error shader\r","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/AudioTypePreviewGenerator.cs#L12-L48","documentation":"Thrown by AudioTypePreviewGenerator.ValidateSettings when _settings.Width is zero or negative. Width defines the texture dimensions for the audio waveform preview image. This validation runs after the base class ValidateSettings (which checks InputPaths and OutputPath).","triggerScenarios":"Calling Generate() or ValidateSettings() on an AudioTypePreviewGenerator with _settings.Width <= 0. The width is used later to create or reinitialize a Texture2D for waveform rendering.","commonSituations":"Audio preview generator settings constructed without setting Width; settings deserialized from config with a missing width; UI control left at 0 for the audio preview dimension.","solutions":["Set _settings.Width to a positive integer (e.g., 512 or 1024) before calling Generate.","Initialize all dimension fields when constructing AudioTypeGeneratorSettings.","Validate settings at the UI layer before allowing preview generation to start."],"exampleFix":"// before\nvar settings = new AudioTypeGeneratorSettings { Width = 0, Height = 256, InputPaths = paths, OutputPath = outPath };\nvar generator = new AudioTypePreviewGenerator(settings);\nawait generator.Generate();\n\n// after\nvar settings = new AudioTypeGeneratorSettings { Width = 1024, Height = 256, InputPaths = paths, OutputPath = outPath };\nvar generator = new AudioTypePreviewGenerator(settings);\nawait generator.Generate();","handlingStrategy":"validation","validationCode":"if (settings.Width <= 0)\n    settings.Width = 1024; // sensible default for waveform width\n// or validate before Generate():\nif (settings.Width <= 0)\n    throw new InvalidOperationException(\"Audio preview Width must be a positive value.\");","typeGuard":"static bool IsValidAudioPreviewDimensions(AudioTypeGeneratorSettings s)\n    => s.Width > 0 && s.Height > 0;","tryCatchPattern":"try\n{\n    await generator.Generate();\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Width must be larger than 0\"))\n{\n    settings.Width = 1024;\n    await generator.Generate();\n}","preventionTips":["Set both Width and Height when constructing AudioTypeGeneratorSettings.","Clamp audio preview dimensions in the UI to a minimum of 1.","Apply defaults after deserialization."],"tags":["unity","asset-store-tools","preview","validation","audio"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}