{"record":{"id":"bfd7228a45dbfb7e","repo":"Unity-Technologies/UnityCsReference","slug":"size-has-to-be-larger-than-1","errorCode":null,"errorMessage":"Size has to be larger than 1","messagePattern":"Size has to be larger than 1","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Audio/StreamedAudioClipPreview.cs","lineNumber":55,"sourceCode":"        }\n\n        struct ClipPreviewDetails\n        {\n            public float[] preview;\n            public int previewSamples;\n            public double normalizedDuration;\n            public double normalizedStart;\n            public double deltaStep;\n            public AudioClip clip;\n            public int previewPixelsToRender;\n            public double localStart;\n            public double localLength;\n            public bool looping;\n\n            public ClipPreviewDetails(AudioClip clip, bool isLooping, int size, double localStart, double localLength)\n            {\n                if (size < 2)\n                    throw new ArgumentException(\"Size has to be larger than 1\");\n\n                if (localLength <= 0)\n                    throw new ArgumentException(\"length has to be longer than zero\", \"localLength\");\n\n                if (localStart < 0)\n                    throw new ArgumentException(\"localStart has to be positive\", \"localStart\");\n\n                if (clip == null)\n                    throw new ArgumentNullException(\"clip\");\n\n                this.clip = clip;\n\n                preview = AudioClipMinMaxOverview.GetOverviewFor(clip);\n\n                if (preview == null)\n                    throw new ArgumentException(\"Clip \" + clip + \"'s overview preview is null\");\n\n                looping = isLooping;","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Audio/StreamedAudioClipPreview.cs#L37-L73","documentation":"ArgumentException thrown by the ClipPreviewDetails constructor when the size parameter is less than 2. The size represents the pixel width of the audio waveform preview, and at least 2 pixels are needed to render a meaningful min/max overview. Values of 0 or 1 are rejected.","triggerScenarios":"Constructing ClipPreviewDetails with size=0 or size=1. Occurs when a preview rendering rect has zero or one pixel width, when a GUILayout/EditorGUILayout width computes to less than 2, or when a cached size value is stale or uninitialized.","commonSituations":"Collapsed or zero-width inspector windows, preview areas that have not been laid out yet (size=0), DPI or scaling edge cases producing tiny dimensions, layout passes during window initialization before dimensions are computed.","solutions":["Clamp the size parameter to a minimum of 2 before constructing ClipPreviewDetails.","Ensure the preview rendering rect has a valid width by waiting for layout to complete.","Guard against collapsed windows: skip preview rendering when the available width is below a threshold.","Log the computed size value when the error occurs to trace the source of the invalid dimension."],"exampleFix":"// before\nvar details = new ClipPreviewDetails(clip, looping, previewSize, start, length);\n// after\nint safeSize = Math.Max(2, previewSize);\nvar details = new ClipPreviewDetails(clip, looping, safeSize, start, length);","handlingStrategy":"validation","validationCode":"// Clamp size to minimum 2 before constructing ClipPreviewDetails\nint safeSize = Math.Max(2, size);\nvar details = new ClipPreviewDetails(clip, looping, safeSize, localStart, localLength);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp preview pixel sizes to a minimum of 2 in all code paths.","Skip waveform rendering when the inspector or preview area is collapsed.","Defer preview construction until layout has computed valid dimensions.","Guard against DPI scaling edge cases that produce tiny pixel dimensions."],"tags":["audio","editor","validation","argument-validation","preview","waveform"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}