{"record":{"id":"c119e0592176e704","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-maximum-size-max","errorCode":null,"errorMessage":"Invalid maximum size: {max}","messagePattern":"Invalid maximum size: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/ContainerWindow.cs","lineNumber":272,"sourceCode":"                float scale = GetBackingScale();\n                rootView.position = new Rect(0, 0, GUIUtility.RoundToPixelGrid(m_PixelRect.width, scale), GUIUtility.RoundToPixelGrid(m_PixelRect.height, scale));\n            }\n        }\n\n        public void OnEnable()\n        {\n            if (m_RootView)\n                m_RootView.Initialize(this);\n            SetBackgroundColor(skinBackgroundColor);\n        }\n\n        public void SetMinMaxSizes(Vector2 min, Vector2 max)\n        {\n            if (!View.IsValidViewSize(min))\n                throw new ArgumentException($\"Invalid minimum size: {min}\");\n\n            if (!View.IsValidViewSize(max))\n                throw new ArgumentException($\"Invalid maximum size: {max}\");\n\n            m_MinSize = min;\n            m_MaxSize = max;\n            Rect r = position;\n            Rect r2 = r;\n            r2.width = Mathf.Clamp(r.width, min.x, max.x);\n            r2.height = Mathf.Clamp(r.height, min.y, max.y);\n            if (r2.width != r.width || r2.height != r.height)\n                position = r2;\n            Internal_SetMinMaxSizes(min, max);\n        }\n\n        static internal bool CanCloseAll(bool includeMainWindow)\n        {\n            using (var pooledObject = ListPool<EditorWindow>.Get(out List<EditorWindow> unsaved))\n            {\n                foreach (var window in windows)\n                {","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/ContainerWindow.cs#L254-L290","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Guard the value: if (!View.IsValidViewSize(max)) max = new Vector2(4000, 4000); before SetMinMaxSizes.","Use a large finite sentinel (e.g. 4000f) instead of float.PositiveInfinity to mean 'effectively unbounded'.","Find the NaN/Infinity source in the size expression (division, InverseLerp, unset serialized field)."],"exampleFix":"// before\nvar maxSize = new Vector2(float.PositiveInfinity, float.PositiveInfinity);\nwindow.SetMinMaxSizes(min, maxSize);\n// after\n// IsValidViewSize rejects Infinity; use a large finite value instead.\nvar maxSize = new Vector2(4000f, 4000f);\nwindow.SetMinMaxSizes(min, maxSize);","handlingStrategy":"validation","validationCode":"static Vector2 SanitizeMax(Vector2 s)\n{\n    if (float.IsNaN(s.x) || float.IsInfinity(s.x)) s.x = 4000f;\n    if (float.IsNaN(s.y) || float.IsInfinity(s.y)) s.y = 4000f;\n    return s;\n}\nmax = SanitizeMax(max);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a large finite sentinel (4000) for 'unbounded' instead of float.PositiveInfinity.","Keep maxSize computations free of division-by-zero-prone denominators.","Validate before setting on any window whose size comes from external layout data."],"tags":["editor","window","ui","validation","nan","size"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}