From 5c9cfde7d50aa85dcd6f552010cbee5dd56152b0 Mon Sep 17 00:00:00 2001 From: flabbet Date: Thu, 13 Feb 2025 10:27:33 +0000 Subject: [PATCH] Fixed fonts disposing --- .env-dev/run-build-bin.nix | 39 ++++++++++++++ .env-dev/run-rider.nix | 35 +++++++++++++ .env-dev/shell.nix | 23 ++++---- .gitignore | 1 + .../Helpers.cs | 5 +- .../MethodInfo.cs | 4 +- .../PixiEditor.ChangeableDocument.Gen.csproj | 52 +++---------------- .../UpdateableChangeActionGenerator.cs | 4 +- src/PixiEditor.Gen/PixiEditor.Gen.csproj | 2 +- .../VectorTextToolExecutor.cs | 20 ++++--- src/PixiEditor/PixiEditor.csproj | 30 +++++------ 11 files changed, 131 insertions(+), 84 deletions(-) create mode 100644 .env-dev/run-build-bin.nix create mode 100644 .env-dev/run-rider.nix diff --git a/.env-dev/run-build-bin.nix b/.env-dev/run-build-bin.nix new file mode 100644 index 000000000..abb8b6e5f --- /dev/null +++ b/.env-dev/run-build-bin.nix @@ -0,0 +1,39 @@ +{ pkgs ? import {} }: + + +(pkgs.buildFHSEnv { + name = "pixieditor-env"; + targetPkgs = pkgs: (with pkgs; [ + dotnet-sdk + avalonia + fontconfig + alsa-lib + glew + udev + gnumake + vulkan-headers + vulkan-loader + vulkan-validation-layers + vulkan-tools + vulkan-tools-lunarg + powershell + ]) ++ (with pkgs.xorg; [ + libX11 + libICE + libSM + libXi + libXcursor + libXext + libXrandr ]); + + multiPkgs = pkgs: (with pkgs; [ + udev + alsa-lib + ]); + + runScript = "nohup ./PixiEditor &"; +}).env + + + + diff --git a/.env-dev/run-rider.nix b/.env-dev/run-rider.nix new file mode 100644 index 000000000..f01d193eb --- /dev/null +++ b/.env-dev/run-rider.nix @@ -0,0 +1,35 @@ +{ pkgs ? import {} }: + + +(pkgs.buildFHSEnv { + name = "rider-env"; + targetPkgs = pkgs: (with pkgs; [ + dotnet-sdk + avalonia + fontconfig + alsa-lib + glew + udev + gnumake + vulkan-headers + vulkan-loader + vulkan-validation-layers + vulkan-tools + vulkan-tools-lunarg + powershell + ]) ++ (with pkgs.xorg; [ + libX11 + libICE + libSM + libXi + libXcursor + libXext + libXrandr ]); + + multiPkgs = pkgs: (with pkgs; [ + udev + alsa-lib + ]); + + runScript = "nohup rider &"; +}).env diff --git a/.env-dev/shell.nix b/.env-dev/shell.nix index e2c984284..12393fe9b 100644 --- a/.env-dev/shell.nix +++ b/.env-dev/shell.nix @@ -1,10 +1,14 @@ -{ pkgs ? import {} }: +{ pkgs ? import { } }: +with pkgs; +let -(pkgs.buildFHSEnv { - name = "rider-env"; - targetPkgs = pkgs: (with pkgs; [ - dotnetCorePackages.dotnet_8.sdk +dotnet = dotnet-sdk; + +in mkShell { + name = "avalonia-env"; + packages = (with pkgs; [ + dotnet avalonia fontconfig alsa-lib @@ -26,10 +30,5 @@ libXext libXrandr ]); - multiPkgs = pkgs: (with pkgs; [ - udev - alsa-lib - ]); - - runScript = "nohup rider &"; -}).env + DOTNET_ROOT = "${dotnet}"; +} diff --git a/.gitignore b/.gitignore index a2c2bde4e..f2cb34748 100644 --- a/.gitignore +++ b/.gitignore @@ -340,3 +340,4 @@ GitIgnore Cache/ .DS_Store +nohup.out diff --git a/src/PixiEditor.ChangeableDocument.Gen/Helpers.cs b/src/PixiEditor.ChangeableDocument.Gen/Helpers.cs index 0aedff5d5..99f2d598a 100644 --- a/src/PixiEditor.ChangeableDocument.Gen/Helpers.cs +++ b/src/PixiEditor.ChangeableDocument.Gen/Helpers.cs @@ -1,4 +1,7 @@ -using System.Text; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/PixiEditor.ChangeableDocument.Gen/MethodInfo.cs b/src/PixiEditor.ChangeableDocument.Gen/MethodInfo.cs index 8b5f6b4fd..d13397e88 100644 --- a/src/PixiEditor.ChangeableDocument.Gen/MethodInfo.cs +++ b/src/PixiEditor.ChangeableDocument.Gen/MethodInfo.cs @@ -1,4 +1,6 @@ -namespace PixiEditor.ChangeableDocument.Gen +using System.Collections.Generic; + +namespace PixiEditor.ChangeableDocument.Gen { internal record struct MethodInfo(string Name, List Arguments, NamespacedType ContainingClass); } diff --git a/src/PixiEditor.ChangeableDocument.Gen/PixiEditor.ChangeableDocument.Gen.csproj b/src/PixiEditor.ChangeableDocument.Gen/PixiEditor.ChangeableDocument.Gen.csproj index 30208fce8..066710c71 100644 --- a/src/PixiEditor.ChangeableDocument.Gen/PixiEditor.ChangeableDocument.Gen.csproj +++ b/src/PixiEditor.ChangeableDocument.Gen/PixiEditor.ChangeableDocument.Gen.csproj @@ -1,57 +1,17 @@  - netstandard2.0 - false + latest enable - true - Latest - Debug;Release;Steam;DevRelease - AnyCPU - - - - True - - - - True - AnyCPU - - - - True - AnyCPU - - - - AnyCPU - - - - AnyCPU - - - - AnyCPU - - - - AnyCPU - - - - AnyCPU - - - - AnyCPU + true - + + + - + \ No newline at end of file diff --git a/src/PixiEditor.ChangeableDocument.Gen/UpdateableChangeActionGenerator.cs b/src/PixiEditor.ChangeableDocument.Gen/UpdateableChangeActionGenerator.cs index 343dcb964..b8ead80ca 100644 --- a/src/PixiEditor.ChangeableDocument.Gen/UpdateableChangeActionGenerator.cs +++ b/src/PixiEditor.ChangeableDocument.Gen/UpdateableChangeActionGenerator.cs @@ -1,4 +1,6 @@ -using Microsoft.CodeAnalysis; +using System.Linq; +using System.Threading; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; diff --git a/src/PixiEditor.Gen/PixiEditor.Gen.csproj b/src/PixiEditor.Gen/PixiEditor.Gen.csproj index 47cd933f5..c06abccc8 100644 --- a/src/PixiEditor.Gen/PixiEditor.Gen.csproj +++ b/src/PixiEditor.Gen/PixiEditor.Gen.csproj @@ -4,7 +4,7 @@ netstandard2.0 true enable - enable + true latest PixiEditorGen diff --git a/src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorTextToolExecutor.cs b/src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorTextToolExecutor.cs index 9bc809a36..198874a8d 100644 --- a/src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorTextToolExecutor.cs +++ b/src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorTextToolExecutor.cs @@ -31,6 +31,8 @@ internal class VectorTextToolExecutor : UpdateableChangeExecutor, ITextOverlayEv private Font? cachedFont; private bool isListeningForValidLayer; private VectorPath? onPath; + + private List fontsToDispose = new(); public override bool BlocksOtherActions => false; @@ -134,6 +136,16 @@ internal class VectorTextToolExecutor : UpdateableChangeExecutor, ITextOverlayEv { internals.ActionAccumulator.AddFinishedActions(new EndSetShapeGeometry_Action()); document.TextOverlayHandler.Hide(); + + foreach (var font in fontsToDispose) + { + if (font != null && !font.IsDisposed) + { + font.Dispose(); + } + } + + fontsToDispose.Clear(); } public void OnTextChanged(string text) @@ -156,12 +168,7 @@ internal class VectorTextToolExecutor : UpdateableChangeExecutor, ITextOverlayEv if (name == nameof(ITextToolbar.FontFamily)) { - Font toDispose = cachedFont; - Dispatcher.UIThread.Post(() => - { - toDispose?.Dispose(); - }); - + fontsToDispose.Add(cachedFont); cachedFont = toolbar.ConstructFont(); document.TextOverlayHandler.Font = cachedFont; } @@ -257,7 +264,6 @@ internal class VectorTextToolExecutor : UpdateableChangeExecutor, ITextOverlayEv AntiAlias = toolbar.AntiAliasing, Path = onPath, // TODO: MaxWidth = toolbar.MaxWidth - // TODO: Path }; } diff --git a/src/PixiEditor/PixiEditor.csproj b/src/PixiEditor/PixiEditor.csproj index e69e1084a..2710f0247 100644 --- a/src/PixiEditor/PixiEditor.csproj +++ b/src/PixiEditor/PixiEditor.csproj @@ -51,7 +51,7 @@ - + @@ -59,15 +59,15 @@ - + - + - + @@ -83,31 +83,31 @@ - + - + - + - + - - - + + + - - + + - + @@ -146,7 +146,7 @@ - +