dotnet 在 UOS 統信系統上運行 UNO 程序輸入時閃爍黑屏問題

本文記錄我在虛擬機內安裝了 UOS 統信系統,運行 UNO 的基於 Skia 的 Gtk 應用程序時,在輸入的過程中不斷窗口閃黑問題

本質上說這個問題和 UNO 毫無關係,這是一個 OpenGL 硬件加速在虛擬機裏運行的問題,問題現象如下

我給 UNO 官方報告了:https://github.com/unoplatform/uno/issues/13530

後面發現是 OpenGL 的一個已知問題,解決方法就是禁用 OpenGL 的加速,完全走軟渲染方式

在 UNO 的 host.Run() 之前加上以下代碼,用來禁用 OpenGL 的加速,規避 OpenGL 在虛擬機裏閃爍黑屏的問題。由於我對 OpenGL 瞭解太少,不知道這麼奇怪的 Bug 的原理是什麼,如果有大佬知道的話,還請告訴我

        host.RenderSurfaceType = RenderSurfaceType.Software;

修改之後的 Program.cs 的代碼大概如下

using GLib;

using System;

using Uno.UI.Runtime.Skia;

namespace UnoApp.Skia.Gtk;
public class Program
{
    public static void Main(string[] args)
    {
        ExceptionManager.UnhandledException += delegate (UnhandledExceptionArgs expArgs)
        {
            Console.WriteLine("GLIB UNHANDLED EXCEPTION" + expArgs.ExceptionObject.ToString());
            expArgs.ExitApplication = true;
        };

        var host = new GtkHost(() => new AppHead(), args);
        host.RenderSurfaceType = RenderSurfaceType.Software; // 這一句是關鍵

        host.Run();
    }
}

本文所有代碼放在 githubgitee 上,可以通過以下方式獲取整個項目的代碼

先創建一個空文件夾,接着使用命令行 cd 命令進入此空文件夾,在命令行裏面輸入以下代碼,即可獲取到本文的代碼

git init
git remote add origin https://gitee.com/lindexi/lindexi_gd.git
git pull origin 9285ee59071c54b49dd6ad0e868a744b4998d203

以上使用的是 gitee 的源,如果 gitee 不能訪問,請替換爲 github 的源。請在命令行繼續輸入以下代碼

git remote remove origin
git remote add origin https://github.com/lindexi/lindexi_gd.git
git pull origin 9285ee59071c54b49dd6ad0e868a744b4998d203

獲取代碼之後,進入 FayjarbeelajoFalfarkeyi 文件夾

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章