Unity-Technologies/UnityCsReference · error · ArgumentException
Invalid minimum size: {min}
Error message
Invalid minimum size: {min} What it means
Thrown by ContainerWindow.SetMinMaxSizes when the 'min' Vector2 fails View.IsValidViewSize. IsValidViewSize rejects any component that is NaN or Infinity (positive or negative). It does NOT enforce positivity or ordering — a zero or negative-but-finite size passes. The check exists because the native windowing layer cannot clamp or apply a non-finite size, so passing garbage (e.g. an uninitialized Vector2 or a size derived from float.NaN math) would corrupt the window rect.
Source
Thrown at Editor/Mono/ContainerWindow.cs:269
if (rootView)
{
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))View on GitHub (pinned to 225b0fbdb5)
Solutions
- Sanitize the size with a guard: if (!View.IsValidViewSize(min)) min = Vector2.one * 100; before calling SetMinMaxSizes.
- Trace where the NaN/Infinity originates — search for division, Mathf.InverseLerp with equal args, or uninitialized serialized Vector2 fields in the window's data.
- If the value comes from a layout pass, defer SetMinMaxSizes until GUILayout/layout has resolved (e.g. in a delayed EditorApplication.delayCall).
Example fix
// before window.SetMinMaxSizes(new Vector2(totalWidth / columnCount, 100), maxSize); // after float safeW = columnCount > 0 ? totalWidth / columnCount : 100f; var min = new Vector2(float.IsNaN(safeW) ? 100f : safeW, 100f); window.SetMinMaxSizes(min, maxSize);
Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidSize(Vector2 s) =>
!float.IsNaN(s.x) && !float.IsNaN(s.y) && !float.IsInfinity(s.x) && !float.IsInfinity(s.y);
// call before SetMinMaxSizes
if (!IsValidSize(min)) min = Vector2.one * 100; Prevention
- Never derive a window size from division without a zero-guard.
- Treat any Vector2 read from an unresolved layout as potentially NaN until layout completes.
- Wrap SetMinMaxSizes in a helper that clamps NaN/Infinity to a sane default.
When it happens
Trigger: Calling ContainerWindow.SetMinMaxSizes(min, max) (directly or via a HostView/EditorWindow minSize setter that flows through) where min.x or min.y is float.NaN or float.PositiveInfinity / float.NegativeInfinity. Commonly reached when min is computed from a division by zero, an unset serialized field, or a RectTransform whose layout has not resolved yet.
Common situations: EditorWindow with minSize computed from layout math that yields NaN (e.g. width / count where count == 0); deserialized window state from a corrupted layout file; custom docking/container code that reads position before the host view is initialized.
Related errors
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/211a3740f5cb146c.
Report an issue: GitHub.