{"record":{"id":"6cfd6ea9a000a636","repo":"Unity-Technologies/UnityCsReference","slug":"length-has-to-be-longer-than-zero","errorCode":null,"errorMessage":"length has to be longer than zero","messagePattern":"length has to be longer than zero","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Audio/StreamedAudioClipPreview.cs","lineNumber":58,"sourceCode":"        {\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;\n\n                this.localStart = localStart;\n                this.localLength = localLength;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Audio/StreamedAudioClipPreview.cs#L40-L76","documentation":"ArgumentException thrown by the ClipPreviewDetails constructor when localLength is zero or negative. localLength defines the duration (in normalized clip time) of the audio segment to preview; a non-positive value would produce an empty or invalid waveform render.","triggerScenarios":"Constructing ClipPreviewDetails with localLength=0 or a negative value. Occurs when the clip's duration computes to zero (empty AudioClip), when a trim region has zero length, or when arithmetic on start/end times yields a non-positive difference.","commonSituations":"Empty or unimported AudioClips with zero samples, trim regions where end equals start, floating-point precision issues producing near-zero or slightly-negative lengths, corrupted or placeholder audio assets.","solutions":["Guard the clip selection: skip preview rendering for clips with zero duration.","Validate localLength > 0 before constructing ClipPreviewDetails.","Ensure trim start/end values produce a positive difference.","Use Mathf.Max(epsilon, localLength) or skip the preview if the computed length is below a small epsilon."],"exampleFix":"// before\nvar details = new ClipPreviewDetails(clip, looping, size, start, localLength);\n// after\nif (localLength <= 0)\n    return; // skip preview for zero-length segments\nvar details = new ClipPreviewDetails(clip, looping, size, start, localLength);","handlingStrategy":"validation","validationCode":"// Validate localLength before constructing ClipPreviewDetails\nif (localLength <= 0)\n{\n    Debug.LogWarning(\"Clip preview localLength must be positive. Skipping preview.\");\n    return;\n}\nvar details = new ClipPreviewDetails(clip, looping, size, localStart, localLength);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check clip.length > 0 before computing localLength.","Ensure trim end > trim start to produce positive localLength.","Guard against zero-length clips by skipping preview rendering.","Use a small epsilon comparison for floating-point localLength values."],"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"}