运行Avalonia时在树莓派4上使用DRM时出现错误。

huangapple go评论126阅读模式
英文:

Error when trying to run Avalonia through DRM in raspberry pi 4

问题

I can't run an Avalonia Application in my Raspberry Pi 4 using Raspberry Os Lite and DRM, I followed all the instructions in this tutorial:
https://docs.avaloniaui.net/guides/deep-dives/running-on-raspbian-lite-via-drm

But I'm getting this error:

Unhandled exception. System.ComponentModel.Win32Exception (95): drmModeGetResources failed
   at Avalonia.LinuxFramebuffer.Output.DrmResources..ctor(Int32 fd) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs:line 89
   at Avalonia.LinuxFramebuffer.Output.DrmOutput..ctor(String path) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs:line 30
   at LinuxFramebufferPlatformExtensions.StartLinuxDrm[T](T builder, String[] args, String card, Double scaling) in /_/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs:line 142

This is my MainWindow.axaml

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:LeanovationHitachi="clr-namespace:LeanovationHitachi"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="480"
        x:Class="LeanovationHitachi.MainWindow"
        HasSystemDecorations="false"
        WindowStartupLocation="CenterScreen"
        Width="800"
        Height="480"
        WindowState="Maximized"
        Title="LeanovationHitachi">
    <LeanovationHitachi:MainView/>
</Window>

This is my MainSingleView.axaml

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:LeanovationHitachi="clr-namespace:LeanovationHitachi"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="LeanovationHitachi.MainSingleView">
    <LeanovationHitachi:MainView/>
</UserControl>

This is my MainView.axaml

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:fa="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="LeanovationHitachi.MainView"
             Width="800"
             Height="480">
    <Border>
        <!-- All my code -->
    </Border>
</UserControl>

This is my Program.cs

using Avalonia;
using Projektanker.Icons.Avalonia;
using Projektanker.Icons.Avalonia.FontAwesome;
using System;
using System.Linq;
using System.Threading;
namespace LeanovationHitachi;

class Program
{
    // Initialization code. Don't use any Avalonia, third-party APIs, or any SynchronizationContext-reliant code before AppMain is called: things aren't initialized yet, and stuff might break.
    [STAThread]
    public static int Main(string[] args)
    {
        var builder = BuildAvaloniaApp();
        if (args.Contains("--drm"))
        {
            SilenceConsole();
            return builder.StartLinuxDrm(args);
        }

        return builder.StartWithClassicDesktopLifetime(args);
    }

    private static void SilenceConsole()
    {
        new Thread(() =>
        {
            Console.CursorVisible = false;
            while (true)
                Console.ReadKey(true);
        })
        { IsBackground = true }.Start();
    }

    // Avalonia configuration, don't remove; also used by the visual designer.
    public static AppBuilder BuildAvaloniaApp()
    {
        return AppBuilder.Configure<App>()
            .UsePlatformDetect()
            .LogToTrace()
            .WithIcons(container => container
                .Register<FontAwesomeIconProvider>());
    }
}

App.axaml.cs

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace LeanovationHitachi;

public partial class App : Application
{
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            desktop.MainWindow = new MainWindow();
        else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
            singleView.MainView = new MainSingleView();

        base.OnFrameworkInitializationCompleted();
    }
}
英文:

I can't run an Avalonia Application in my Raspberry Pi 4 using Raspberry Os Lite and DRM, I followed all the instructions in this tutorial:
https://docs.avaloniaui.net/guides/deep-dives/running-on-raspbian-lite-via-drm

But I'm getting this error:

Unhandled exception. System.ComponentModel.Win32Exception (95): drmModeGetResources failed
   at Avalonia.LinuxFramebuffer.Output.DrmResources..ctor(Int32 fd) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs:line 89
   at Avalonia.LinuxFramebuffer.Output.DrmOutput..ctor(String path) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs:line 30
   at LinuxFramebufferPlatformExtensions.StartLinuxDrm[T](T builder, String[] args, String card, Double scaling) in /_/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs:line 142

This is my MainWindow.axaml

&lt;Window xmlns=&quot;https://github.com/avaloniaui&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
        xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
         xmlns:LeanovationHitachi=&quot;clr-namespace:LeanovationHitachi&quot;
		mc:Ignorable=&quot;d&quot; d:DesignWidth=&quot;800&quot; d:DesignHeight=&quot;480&quot;
        x:Class=&quot;LeanovationHitachi.MainWindow&quot;
		HasSystemDecorations=&quot;false&quot;
		WindowStartupLocation=&quot;CenterScreen&quot;
		Width=&quot;800&quot;
		Height=&quot;480&quot;
		WindowState=&quot;Maximized&quot;
        Title=&quot;LeanovationHitachi&quot;&gt;
	&lt;LeanovationHitachi:MainView/&gt;
&lt;/Window&gt;

This is my MainSingleView.axaml

&lt;UserControl xmlns=&quot;https://github.com/avaloniaui&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
             xmlns:LeanovationHitachi=&quot;clr-namespace:LeanovationHitachi&quot;
			 mc:Ignorable=&quot;d&quot; d:DesignWidth=&quot;800&quot; d:DesignHeight=&quot;450&quot;
             x:Class=&quot;LeanovationHitachi.MainSingleView&quot;&gt;
	&lt;LeanovationHitachi:MainView/&gt;
&lt;/UserControl&gt;

This is my MainView.axaml

&lt;UserControl xmlns=&quot;https://github.com/avaloniaui&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
             xmlns:fa=&quot;clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia&quot;
			 mc:Ignorable=&quot;d&quot; d:DesignWidth=&quot;800&quot; d:DesignHeight=&quot;450&quot;
             x:Class=&quot;LeanovationHitachi.MainView&quot;
			 Width=&quot;800&quot;
			 Height=&quot;480&quot;&gt;
	&lt;Border&gt;
//All my code
&lt;/Border&gt;
&lt;/UserControl&gt;

This is my Program.cs

using Avalonia;
using Projektanker.Icons.Avalonia;
using Projektanker.Icons.Avalonia.FontAwesome;
using System;
using System.Linq;
using System.Threading;
namespace LeanovationHitachi;

class Program
{
    // Initialization code. Don&#39;t use any Avalonia, third-party APIs or any
    // SynchronizationContext-reliant code before AppMain is called: things aren&#39;t initialized
    // yet and stuff might break.
    [STAThread]
    public static int Main(string[] args)
    {
        var builder = BuildAvaloniaApp();
        if (args.Contains(&quot;--drm&quot;))
        {
            SilenceConsole();
            return builder.StartLinuxDrm(args);
        }

        return builder.StartWithClassicDesktopLifetime(args);
    }

    private static void SilenceConsole()
    {
        new Thread(() =&gt;
        {
            Console.CursorVisible = false;
            while (true)
                Console.ReadKey(true);
        })
        { IsBackground = true }.Start();
    }

    // Avalonia configuration, don&#39;t remove; also used by visual designer.
    public static AppBuilder BuildAvaloniaApp()
    {
        return AppBuilder.Configure&lt;App&gt;()
            .UsePlatformDetect()
            .LogToTrace()
            .WithIcons(container =&gt; container
                .Register&lt;FontAwesomeIconProvider&gt;());
    }
}

App.axaml.cs

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace LeanovationHitachi;

public partial class App : Application
{
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            desktop.MainWindow = new MainWindow();
        else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
            singleView.MainView = new MainSingleView();

        base.OnFrameworkInitializationCompleted();
    }
}

答案1

得分: 1

确保启用VC4 V3D驱动程序。使用nano或将SD卡连接到计算机,并找到引导分区中的config.txt文件。

# 启用DRM VC4 V3D驱动程序
dtoverlay=vc4-kms-v3d

并且不要忘记使用--drm参数运行您的应用程序。

./LeanovationHitachi --drm
英文:

Make sure you enable the VC4 V3D driver. Use nano or attach your SD card to your computer and find the config.txt file in the boot partition.

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d

And do not forget to run your app with --drm

./LeanovationHitachi --drm

答案2

得分: 0

我通过将所有参数添加到方法调用中来解决了这个问题:

if (args.Contains("--drm"))
{
    SilenceConsole();
    return builder.StartLinuxDrm(args: args, card: "/dev/dri/card1", scaling: 1.0);
}
英文:

I solved this problem by adding all parameters to the method call:

if (args.Contains(&quot;--drm&quot;))
{
    SilenceConsole();
    return builder.StartLinuxDrm(args: args, card: &quot;/dev/dri/card1&quot;, scaling: 1.0);
}

huangapple
  • 本文由 发表于 2023年4月7日 03:01:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定