{"record":{"id":"3d8ff5b6e0412972","repo":"dotnet/wpf","slug":"sr-clustermapentryshouldpointwithinglyphindices","errorCode":null,"errorMessage":"SR.ClusterMapEntryShouldPointWithinGlyphIndices","messagePattern":"SR\\.ClusterMapEntryShouldPointWithinGlyphIndices","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs","lineNumber":387,"sourceCode":"                            {\n                                int glyphCount = GlyphCount;\n                                int mapCount = clusterMap.Count;\n                                ushort previous = clusterMap[0];\n\n                                for (int i = 1; i < mapCount; ++i)\n                                {\n                                    ushort current = clusterMap[i];\n                                    if ((current >= previous) && (current < glyphCount))\n                                    {\n                                        previous = current;\n                                    }\n                                    else\n                                    {\n                                        if (clusterMap[i] < clusterMap[i - 1])\n                                            throw new ArgumentException(SR.ClusterMapEntriesShouldNotDecrease, nameof(clusterMap));\n\n                                        if (clusterMap[i] >= GlyphCount)\n                                            throw new ArgumentException(SR.ClusterMapEntryShouldPointWithinGlyphIndices, nameof(clusterMap));\n                                    }\n                                }\n                            }\n                            else\n                            {\n                                throw new ArgumentException(SR.ClusterMapFirstEntryMustBeZero, nameof(clusterMap));\n                            }\n                        }\n                        else\n                        {\n                            throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsShouldBeEqualTo, characters.Count), nameof(clusterMap));\n                        }\n                    }\n                    else\n                    {\n                        if (GlyphCount != characters.Count)\n                            throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsShouldBeEqualTo, GlyphCount), nameof(clusterMap));\n                    }","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs#L369-L405","documentation":"GlyphRun.Initialize requires every clusterMap entry to point to a valid glyph index position: clusterMap[i] must be < GlyphCount. An entry at or beyond the glyph count has no corresponding glyph, so the run is invalid. It throws ArgumentException naming the clusterMap parameter.","triggerScenarios":"Constructing a GlyphRun (constructor, TryCreate, or EndInit) where clusterMap contains a value >= glyphIndices.Count, typically after shrinking glyphIndices without updating the cluster map.","commonSituations":"Trimming glyphs from a run but leaving the original cluster map; building clusterMap with 1-based or character-count-based indices while expecting glyph-index semantics.","solutions":["Clamp or rebuild clusterMap so every entry is < GlyphCount","Recompute the cluster map after any change to glyphIndices","Validate with clusterMap.All(v => v < glyphIndices.Count) before calling the API"],"exampleFix":"// before\nint[] clusterMap = { 0, 5 }; // glyphs.Count == 3\n// after\nint[] clusterMap = { 0, 2 }; // entries within [0, GlyphCount)","handlingStrategy":"validation","validationCode":"if (clusterMap != null && clusterMap.Any(v => v < 0 || v >= glyphIndices.Count))\n    throw new ArgumentException(\"clusterMap entry out of glyph range\");","typeGuard":"static bool EntriesWithinGlyphs(int[] map, int glyphCount) => map == null || map.All(v => v >= 0 && v < glyphCount);","tryCatchPattern":"try { var run = new GlyphRun(...); }\ncatch (ArgumentException ex) when (ex.ParamName == \"clusterMap\") { /* regenerate map */ }","preventionTips":["Update clusterMap whenever glyphIndices is resized","Assert map.All(v => v < glyphCount) in debug builds","Prefer null clusterMap for 1:1 runs"],"tags":["wpf","glyphrun","argument-validation"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}