英文:
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
<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 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();
    }
}
答案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("--drm"))
{
    SilenceConsole();
    return builder.StartLinuxDrm(args: args, card: "/dev/dri/card1", scaling: 1.0);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论