Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLE: Refactoring of ApplicationLoader #4480

Merged
merged 21 commits into from
Mar 31, 2023
Merged

Conversation

AcK77
Copy link
Member

@AcK77 AcK77 commented Feb 25, 2023

This PR attempt to refactor ApplicationLoader in a better way for avoid duplicated code and helping in a potential multi-processes support in the future.

In that way, some things are a bit "wrong" but should works as expected since we can only run one Application at a time.
I've done some loading testing but it could be nice to test different loading too, like Homebrew, NSP Homebrew, games using jit services, and more...

@AcK77 AcK77 added enhancement New feature or request horizon Related to Ryujinx.HLE labels Feb 25, 2023
Copy link
Member

@gdkchan gdkchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a quick look, I will likely submit another review after testing it a bit and checking out the changes locally.

Ryujinx.Ava/AppHost.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/HOS/ModLoader.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/Extensions/NcaExtensions.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/Extensions/NcaExtensions.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/Extensions/NcaExtensions.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/ProcessInfo.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/ProcessInfo.cs Outdated Show resolved Hide resolved
Ryujinx.Ui.Common/App/ApplicationLibrary.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/ProcessResult.cs Outdated Show resolved Hide resolved
Copy link
Member

@TSRBerry TSRBerry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just found a few typos

Copy link
Member

@gdkchan gdkchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I tested it a bit here, but did not test it extensively, so it might benefit from more testing in different scenarios.

@TSRBerry
Copy link
Member

I'm not able to start homebrew applications with this PR.

The crash below was produced using the hello-world example from switchbrew/switch-examples.

crash snippet:

00:00:00.362 |I| Application LoadGuestApplication: Loading as homebrew.
00:00:00.376 |W| Loader GetNpdm: NPDM file not found, using default values!
00:00:00.395 |E| Application : Unhandled exception caught: LibHac.Common.HorizonResultException: ResultLoaderInvalidMeta (2009-0004)
   at LibHac.Common.ThrowHelper.ThrowResult(Result result)
   at LibHac.Result.ThrowIfFailure()
   at Ryujinx.HLE.Loaders.Processes.Extensions.MetaLoaderExtensions.LoadDefault(MetaLoader metaLoader) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Loaders/Processes/Extensions/MetaLoaderExtensions.cs:line 38
   at Ryujinx.HLE.Loaders.Processes.Extensions.FileSystemExtensions.GetNpdm(IFileSystem fileSystem) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs:line 26
   at Ryujinx.HLE.Loaders.Processes.ProcessLoader.LoadNxo(String path) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs:line 178
   at Ryujinx.HLE.Switch.LoadProgram(String fileName) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Switch.cs:line 90
   at Ryujinx.Ava.AppHost.LoadGuestApplication() in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.Ava/AppHost.cs:line 605
   at Ryujinx.Ava.UI.ViewModels.MainWindowViewModel.<>c__DisplayClass369_0.<<LoadApplication>g__Action|0>d.MoveNext() in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs:line 1694
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Avalonia.Threading.AvaloniaSynchronizationContext.<>c__DisplayClass5_0.<Post>b__0() in /_/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs:line 33
   at Avalonia.X11.X11PlatformThreading.CheckSignaled() in /_/src/Avalonia.X11/X11PlatformThreading.cs:line 164
   at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken) in /_/src/Avalonia.X11/X11PlatformThreading.cs:line 244
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.cs:line 65
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 120
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 209
   at Ryujinx.Ava.Program.Main(String[] args) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.Ava/Program.cs:line 51

TSRBerry
TSRBerry previously approved these changes Mar 12, 2023
Copy link
Member

@TSRBerry TSRBerry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

I'll ask for some community tests, before we merge this.
I tested cheats and homebrew applications, but haven't tested a lot of other stuff.

@TSRBerry TSRBerry added the needs-feedback The needs feedbacks from the community label Mar 12, 2023
@MisterbALLIN
Copy link

Tested Splatoon 3 with the Inkopolis DLC on Update 3.0.1. Everything seems good

@LukeWarnut
Copy link
Contributor

Tested Splatoon 3 with the Flexlion mod and DLCs, Hollow Knight, Resident Evil 4, and Dead Cells + DLC; all using the latest updates. No regressions found.

@TSRBerry TSRBerry dismissed their stale review March 13, 2023 00:43

With the amount of commits I'm adding, another review will be required.

@TSRBerry
Copy link
Member

TSRBerry commented Mar 13, 2023

I found a few more issues:

  • If ProcessResult.Failed was returned Ryujinx would crash with a NRE.

    Example crash
    ```
    00:00:00.351 |I| Application LoadGuestApplication: Loading as NSP.
    00:00:00.355 |E| Loader Load: Unable to load: Could not find Main NCA
    00:00:00.361 |E| Application : Unhandled exception caught: System.NullReferenceException: Object reference not set to an instance of an object.
       at Ryujinx.HLE.Loaders.Processes.Extensions.MetaLoaderExtensions.GetProgramId(MetaLoader metaLoader) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Loaders/Processes/Extensions/MetaLoaderExtensions.cs:line 15
       at Ryujinx.HLE.Loaders.Processes.ProcessResult..ctor(MetaLoader metaLoader, ApplicationControlProperty applicationControlProperties, Boolean diskCacheEnabled, Boolean allowCodeMemoryForJit, IDiskCacheLoadState diskCacheLoadState, UInt64 pid, Byte mainThreadPriority, UInt32 mainThreadStackSize) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs:line 48
       at Ryujinx.HLE.Loaders.Processes.ProcessResult.get_Failed() in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs:line 12
       at Ryujinx.HLE.Loaders.Processes.Extensions.PartitionFileSystemExtensions.Load(PartitionFileSystem partitionFileSystem, Switch device, String path) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Loaders/Processes/Extensions/PartitionFileSystemExtensions.cs:line 163
       at Ryujinx.HLE.Loaders.Processes.ProcessLoader.LoadNsp(String path) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs:line 61
       at Ryujinx.HLE.Switch.LoadNsp(String nspFile) in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.HLE/Switch.cs:line 85
       at Ryujinx.Ava.AppHost.LoadGuestApplication() in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.Ava/AppHost.cs:line 595
       at Ryujinx.Ava.UI.ViewModels.MainWindowViewModel.<>c__DisplayClass369_0.<<LoadApplication>g__Action|0>d.MoveNext() in /mnt/Dev/git-repos/Nintendo/Ryujinx/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs:line 1694
    ```
    
  • Error logging was a little confusing when loading nx-hbloader, as it would first log an error and then continue to load without issues.

  • None of the GUIs were checking the results of the Load() calls.

@TSRBerry
Copy link
Member

Rebased, ready for another review!

Ryujinx.HLE/Loaders/Processes/Extensions/NcaExtensions.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs Outdated Show resolved Hide resolved

(bool success, ProcessResult processResult) = partitionFileSystem.TryLoad(_device, path, out string errorMessage);

if (processResult.ProcessId == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit odd, is it using ProcessId == 0 as an indication that the load failed? Why does it not just check if success is false?

Copy link
Member

@gdkchan gdkchan Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the other methods are doing this too (since they don't have a success return value). So maybe it's better to keep it like this for the sake of consistency. Also I didn't check the case where it returns success, so it's possible that it wouldn't even work here, but that would be a bit misleading (you would assume that if success is true, everything loaded correctly).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it will only return true if loading succeeded here.
I agree it's a bit confusing, but wasn't sure to change the check here if we are doing it this way for every other load method like this.

Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs Outdated Show resolved Hide resolved
Ryujinx.HLE/Loaders/Processes/ProcessResult.cs Outdated Show resolved Hide resolved
@TSRBerry TSRBerry requested a review from gdkchan March 21, 2023 20:34
@marysaka marysaka merged commit 4c2d9ff into Ryujinx:master Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request horizon Related to Ryujinx.HLE needs-feedback The needs feedbacks from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants