我无法在我的树莓派4上运行Avalonia应用程序,使用树莓Os Lite和DRM,我遵循了本教程中的所有说明:https://docs.avaloniaui.net/guides/deep-dives/running-on-raspbian-lite-via-drm
但是我得到这个错误:
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
这是我的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>
这是我的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>
这是我的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>
这是我的程序。
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();
}
}
确保您启用了VC4 V3D驱动程序。使用nano或将SD卡连接到计算机上,并在引导分区中找到config.txt
文件。
# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
不要忘记使用——drm
运行你的应用./LeanovationHitachi --drm
我通过将所有参数添加到方法调用中来解决这个问题:
if (args.Contains("--drm"))
{
SilenceConsole();
return builder.StartLinuxDrm(args: args, card: "/dev/dri/card1", scaling: 1.0);
}