AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.96k stars 2.25k forks source link

System.InvalidOperationException: Could not create glyphTypeface on Linux after upgrade to version 11.1.x #16612

Closed sandsc closed 3 months ago

sandsc commented 3 months ago

Describe the bug

Gets InvalidOperation while app startup, It works on 11.0.x version.

System.InvalidOperationException: Could not create glyphTypeface. Font family: $Default (key: ). Style: Normal. Weight: Normal. Stretch: Normal
   at Avalonia.Media.Typeface.get_GlyphTypeface()
   at Avalonia.Rendering.Composition.Compositor.get_DiagnosticTextRenderer()
   at Avalonia.Rendering.Composition.Compositor.CreateCompositionTarget(Func`1 surfaces)
   at Avalonia.Rendering.Composition.CompositingRenderer..ctor(IRenderRoot root, Compositor compositor, Func`1 surfaces)
   at Avalonia.Controls.TopLevel..ctor(ITopLevelImpl impl, IAvaloniaDependencyResolver dependencyResolver)
   at Avalonia.Controls.WindowBase..ctor(IWindowBaseImpl impl, IAvaloniaDependencyResolver dependencyResolver)
   at Avalonia.Controls.WindowBase..ctor(IWindowBaseImpl impl)
   at Avalonia.Controls.Window..ctor(IWindowImpl impl)
   at Avalonia.Controls.Window..ctor()

To Reproduce

Create a default Avalonia app using Project template by using version 11.1.x, run it on linux, e.c. ubuntu or kylinOS v10.

Expected behavior

The app starts normally

Avalonia version

11.1.x

OS

Linux

Additional context

No response

nicewillsuccess commented 3 months ago

I, too, did you find a solution?

lindexi commented 3 months ago

@sandsc You should add the font options in Kylin os:

        appBuilder.With(new FontManagerOptions()
        {
            DefaultFamilyName = "Noto Sans CJK SC",
            FontFallbacks =
            [
                new FontFallback { FontFamily = "文泉驿正黑" },
                new FontFallback { FontFamily = "DejaVu Sans" },
            ],
        });

I wrote the Chinese blog in https://blog.lindexi.com/post/dotnet-%E8%A7%A3%E5%86%B3-Avalonia-%E5%9C%A8-OpenKylin-%E9%BA%92%E9%BA%9F%E7%B3%BB%E7%BB%9F%E8%BF%90%E8%A1%8C%E6%89%BE%E4%B8%8D%E5%88%B0%E9%BB%98%E8%AE%A4%E5%AD%97%E4%BD%93%E5%90%AF%E5%8A%A8%E5%A4%B1%E8%B4%A5.html

sandsc commented 3 months ago

@sandsc You should add the font options in Kylin os:

        appBuilder.With(new FontManagerOptions()
        {
            DefaultFamilyName = "Noto Sans CJK SC",
            FontFallbacks =
            [
                new FontFallback { FontFamily = "文泉驿正黑" },
                new FontFallback { FontFamily = "DejaVu Sans" },
            ],
        });

I wrote the Chinese blog in https://blog.lindexi.com/post/dotnet-%E8%A7%A3%E5%86%B3-Avalonia-%E5%9C%A8-OpenKylin-%E9%BA%92%E9%BA%9F%E7%B3%BB%E7%BB%9F%E8%BF%90%E8%A1%8C%E6%89%BE%E4%B8%8D%E5%88%B0%E9%BB%98%E8%AE%A4%E5%AD%97%E4%BD%93%E5%90%AF%E5%8A%A8%E5%A4%B1%E8%B4%A5.html

Thanks, I fixed this for now by using your method, but v11.0.x doesn't have this issue. Is this an API change or a bug?

Gillibald commented 3 months ago

If it worked before it should still work with newer Avalonia. But in the end there is nothing we can do if the FontManager isn't providing a default.

a6754z commented 3 weeks ago

This is indeed a bug but the above workaround works.