Unity-Technologies/UnityCsReference · error · ArgumentException
localStart has to be positive
Error message
localStart has to be positive
What it means
ArgumentException thrown by the ClipPreviewDetails constructor when localStart is negative. localStart represents the starting position within the AudioClip (in normalized time); a negative value would point before the clip's beginning and produce an invalid preview region.
Source
Thrown at Editor/Mono/Audio/StreamedAudioClipPreview.cs:61
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;
if (looping)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Clamp localStart to a minimum of 0 before constructing ClipPreviewDetails.
- Validate UI inputs for trim/loop start positions to disallow negative values.
- Use Mathf.Clamp(localStart, 0, 1) to ensure the value is within the clip's normalized range.
- Log the computed localStart when the error occurs to trace the calculation producing the negative value.
Example fix
// before var details = new ClipPreviewDetails(clip, looping, size, localStart, length); // after double safeStart = Math.Max(0, localStart); var details = new ClipPreviewDetails(clip, looping, size, safeStart, length);
Defensive patterns
Strategy: validation
Validate before calling
// Clamp localStart to minimum 0 before constructing ClipPreviewDetails double safeStart = Math.Max(0, localStart); var details = new ClipPreviewDetails(clip, looping, size, safeStart, localLength);
Prevention
- Clamp localStart to [0, 1] range for normalized clip positions.
- Validate UI controls for trim/loop start to disallow negative values.
- Use Mathf.Clamp on scrubber and timeline positions.
- Log computed localStart values during debugging to trace negative-value sources.
When it happens
Trigger: Constructing ClipPreviewDetails with a localStart value below zero. Occurs when a trim offset or loop start position is set to a negative value, or when floating-point arithmetic on normalized positions underflows below zero.
Common situations: Loop or trim UI controls that allow negative start values without clamping, serialized properties with incorrect default values, arithmetic errors when converting sample offsets to normalized time, animation or scrubber interactions that compute positions outside the valid range.
Related errors
- Size has to be larger than 1
- length has to be longer than zero
- 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/23d3d36db1d0be8b.
Report an issue: GitHub.