Unity-Technologies/UnityCsReference · error · ArgumentException
length has to be longer than zero
Error message
length has to be longer than zero
What it means
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.
Source
Thrown at Editor/Mono/Audio/StreamedAudioClipPreview.cs:58
{
public float[] preview;
public int previewSamples;
public double normalizedDuration;
public double normalizedStart;
public double deltaStep;
public AudioClip clip;
public int previewPixelsToRender;
public double localStart;
public double localLength;
public bool looping;
public ClipPreviewDetails(AudioClip clip, bool isLooping, int size, double localStart, double localLength)
{
if (size < 2)
throw new ArgumentException("Size has to be larger than 1");
if (localLength <= 0)
throw new ArgumentException("length has to be longer than zero", "localLength");
if (localStart < 0)
throw new ArgumentException("localStart has to be positive", "localStart");
if (clip == null)
throw new ArgumentNullException("clip");
this.clip = clip;
preview = AudioClipMinMaxOverview.GetOverviewFor(clip);
if (preview == null)
throw new ArgumentException("Clip " + clip + "'s overview preview is null");
looping = isLooping;
this.localStart = localStart;
this.localLength = localLength;View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
var details = new ClipPreviewDetails(clip, looping, size, start, localLength);
// after
if (localLength <= 0)
return; // skip preview for zero-length segments
var details = new ClipPreviewDetails(clip, looping, size, start, localLength); Defensive patterns
Strategy: validation
Validate before calling
// Validate localLength before constructing ClipPreviewDetails
if (localLength <= 0)
{
Debug.LogWarning("Clip preview localLength must be positive. Skipping preview.");
return;
}
var details = new ClipPreviewDetails(clip, looping, size, localStart, localLength); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Size has to be larger than 1
- localStart has to be positive
- clip
- Clip {clip}'s overview preview is null
- Must be greater than zero.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/6cfd6ea9a000a636.
Report an issue: GitHub.