From 1078ad4a075e56ac23377ed553be1f6b6a5184d5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 21 Feb 2023 17:07:41 +0900 Subject: [PATCH] Fix potential crash when displaying `DirectorySelector` on AOT platforms --- .../UserInterface/DirectorySelector.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/osu.Framework/Graphics/UserInterface/DirectorySelector.cs b/osu.Framework/Graphics/UserInterface/DirectorySelector.cs index 68f1b19d4e..228e5a7d87 100644 --- a/osu.Framework/Graphics/UserInterface/DirectorySelector.cs +++ b/osu.Framework/Graphics/UserInterface/DirectorySelector.cs @@ -138,8 +138,6 @@ private void updateDisplay() { directoryChanging = true; - directoryFlow.Clear(); - var newDirectory = CurrentPath.Value; bool notifyError = false; ICollection items = Array.Empty(); @@ -160,16 +158,27 @@ private void updateDisplay() if (newDirectory == null) { - var drives = DriveInfo.GetDrives(); + try + { + // This will throw on AOT platforms (System.ExecutionEngineException: Attempting to JIT compile method). + var drives = DriveInfo.GetDrives(); + + directoryFlow.Clear(); - foreach (var drive in drives) - directoryFlow.Add(CreateDirectoryItem(drive.RootDirectory)); + foreach (var drive in drives) + directoryFlow.Add(CreateDirectoryItem(drive.RootDirectory)); + } + catch + { + NotifySelectionError(); + } return; } CurrentPath.Value = newDirectory; + directoryFlow.Clear(); directoryFlow.Add(CreateParentDirectoryItem(newDirectory.Parent)); directoryFlow.AddRange(items); }