{"record":{"id":"00bb4afce5d686eb","repo":"AvaloniaUI/Avalonia","slug":"glyphrun-00bb4a","errorCode":null,"errorMessage":"glyphRun","messagePattern":"glyphRun","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/PlatformDrawingContext.cs","lineNumber":60,"sourceCode":"        _impl.DrawBitmap(source.Item, opacity, sourceRect, destRect);\n\n    public override void Custom(ICustomDrawOperation custom)\n    {\n        using var immediateDrawingContext = new ImmediateDrawingContext(_impl, false);\n        try\n        {\n            custom.Render(immediateDrawingContext);\n        }\n        catch (Exception e)\n        {\n            Logger.TryGet(LogEventLevel.Error, LogArea.Visual)\n                ?.Log(custom, $\"Exception in {custom.GetType().Name}.{nameof(ICustomDrawOperation.Render)} {{0}}\", e);\n        }\n    }\n\n    public override void DrawGlyphRun(IBrush? foreground, GlyphRun glyphRun)\n    {\n        _ = glyphRun ?? throw new ArgumentNullException(nameof(glyphRun));\n\n        if (foreground != null) \n            _impl.DrawGlyphRun(foreground, glyphRun.PlatformImpl.Item);\n    }\n\n    protected override void PushClipCore(RoundedRect rect) => _impl.PushClip(rect);\n\n    protected override void PushClipCore(Rect rect) => _impl.PushClip(rect);\n\n    protected override void PushGeometryClipCore(Geometry clip) =>\n        _impl.PushGeometryClip(clip.PlatformImpl ?? throw new ArgumentException());\n\n    protected override void PushOpacityCore(double opacity) => \n        _impl.PushOpacity(opacity, null);\n\n    protected override void PushOpacityMaskCore(IBrush mask, Rect bounds) =>\n        _impl.PushOpacityMask(mask, bounds);\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/PlatformDrawingContext.cs#L42-L78","documentation":"Thrown by PlatformDrawingContext.DrawGlyphRun when the GlyphRun argument is null. The drawing context dereferences glyphRun.PlatformImpl immediately, so a null reference cannot proceed; the explicit guard produces a clear ArgumentNullException instead of a NullReferenceException deeper in the stack.","triggerScenarios":"Calling DrawGlyphRun(foreground, null) directly, or passing a GlyphRun field/property that was never constructed.","commonSituations":"Rendering text where the GlyphRun was built from a null glyph typeface or zero-length text and ended up null; conditional text rendering that passes null when 'no text' was intended.","solutions":["Pass null for the foreground brush to draw nothing, or simply skip the DrawGlyphRun call when there is no glyph run.","Ensure the GlyphRun is constructed from a valid GlyphTypeface and non-empty metrics before drawing.","Guard: if (glyphRun is not null) context.DrawGlyphRun(foreground, glyphRun);"],"exampleFix":"// before\ncontext.DrawGlyphRun(foreground, null);\n\n// after\nif (glyphRun is not null)\n    context.DrawGlyphRun(foreground, glyphRun);","handlingStrategy":"validation","validationCode":"if (glyphRun is not null)\n    context.DrawGlyphRun(foreground, glyphRun);","typeGuard":"static bool HasGlyphRun(GlyphRun? run) => run is not null;","tryCatchPattern":null,"preventionTips":["Skip the draw call when there is no glyph run rather than passing null.","Construct GlyphRun only from a valid GlyphTypeface and non-empty metrics."],"tags":["avalonia","drawing-context","glyph","null-argument","text"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}