Unity-Technologies/UnityCsReference · error · ArgumentException

Size has to be larger than 1

Error message

Size has to be larger than 1

What it means

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.

Source

Thrown at Editor/Mono/Audio/StreamedAudioClipPreview.cs:55

        }

        struct ClipPreviewDetails
        {
            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;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Clamp the size parameter to a minimum of 2 before constructing ClipPreviewDetails.
  2. Ensure the preview rendering rect has a valid width by waiting for layout to complete.
  3. Guard against collapsed windows: skip preview rendering when the available width is below a threshold.
  4. Log the computed size value when the error occurs to trace the source of the invalid dimension.

Example fix

// before
var details = new ClipPreviewDetails(clip, looping, previewSize, start, length);
// after
int safeSize = Math.Max(2, previewSize);
var details = new ClipPreviewDetails(clip, looping, safeSize, start, length);
Defensive patterns

Strategy: validation

Validate before calling

// Clamp size to minimum 2 before constructing ClipPreviewDetails
int safeSize = Math.Max(2, size);
var details = new ClipPreviewDetails(clip, looping, safeSize, localStart, localLength);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/bfd7228a45dbfb7e. Report an issue: GitHub.