Unity-Technologies/UnityCsReference · error · ArgumentException

Invalid maximum size: {max}

Error message

Invalid maximum size: {max}

What it means

Thrown by ContainerWindow.SetMinMaxSizes when the 'max' Vector2 fails View.IsValidViewSize. The same IsValidViewSize predicate is used as for min: it only rejects NaN and Infinity. Note max is allowed to be smaller than min by this check — the native call Internal_SetMinMaxSizes is invoked unconditionally with the pair, so an inverted min/max is not caught here.

Source

Thrown at Editor/Mono/ContainerWindow.cs:272

                float scale = GetBackingScale();
                rootView.position = new Rect(0, 0, GUIUtility.RoundToPixelGrid(m_PixelRect.width, scale), GUIUtility.RoundToPixelGrid(m_PixelRect.height, scale));
            }
        }

        public void OnEnable()
        {
            if (m_RootView)
                m_RootView.Initialize(this);
            SetBackgroundColor(skinBackgroundColor);
        }

        public void SetMinMaxSizes(Vector2 min, Vector2 max)
        {
            if (!View.IsValidViewSize(min))
                throw new ArgumentException($"Invalid minimum size: {min}");

            if (!View.IsValidViewSize(max))
                throw new ArgumentException($"Invalid maximum size: {max}");

            m_MinSize = min;
            m_MaxSize = max;
            Rect r = position;
            Rect r2 = r;
            r2.width = Mathf.Clamp(r.width, min.x, max.x);
            r2.height = Mathf.Clamp(r.height, min.y, max.y);
            if (r2.width != r.width || r2.height != r.height)
                position = r2;
            Internal_SetMinMaxSizes(min, max);
        }

        static internal bool CanCloseAll(bool includeMainWindow)
        {
            using (var pooledObject = ListPool<EditorWindow>.Get(out List<EditorWindow> unsaved))
            {
                foreach (var window in windows)
                {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Guard the value: if (!View.IsValidViewSize(max)) max = new Vector2(4000, 4000); before SetMinMaxSizes.
  2. Use a large finite sentinel (e.g. 4000f) instead of float.PositiveInfinity to mean 'effectively unbounded'.
  3. Find the NaN/Infinity source in the size expression (division, InverseLerp, unset serialized field).

Example fix

// before
var maxSize = new Vector2(float.PositiveInfinity, float.PositiveInfinity);
window.SetMinMaxSizes(min, maxSize);
// after
// IsValidViewSize rejects Infinity; use a large finite value instead.
var maxSize = new Vector2(4000f, 4000f);
window.SetMinMaxSizes(min, maxSize);
Defensive patterns

Strategy: validation

Validate before calling

static Vector2 SanitizeMax(Vector2 s)
{
    if (float.IsNaN(s.x) || float.IsInfinity(s.x)) s.x = 4000f;
    if (float.IsNaN(s.y) || float.IsInfinity(s.y)) s.y = 4000f;
    return s;
}
max = SanitizeMax(max);

Prevention

When it happens

Trigger: Calling ContainerWindow.SetMinMaxSizes(min, max) where max.x or max.y is float.NaN or float.PositiveInfinity. A frequent shape is setting maxSize to 'unbounded' by assigning float.MaxValue (finite, passes) but accidentally using float.PositiveInfinity, or computing max from a NaN-bearing min.

Common situations: EditorWindow.maxSize set from RectTransform.rect.size before layout resolves; a 'fill available space' computation that divides by zero screen dimension; copy-paste of a maxSize expression that references an uninitialized variable.

Related errors


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