fix: Change the order of probing for loading native libraries#3033
fix: Change the order of probing for loading native libraries#3033Eideren merged 2 commits intostride3d:masterfrom
Conversation
* Also, modernize the `NativeLibraryLoader` class. * Add documentation, improve the existing comments. * Add debug switch to diagnose library loading problems.
ac5fd6a to
1b9b87f
Compare
|
Does it work and/or fix issues with code-only projects on Linux? I remember we had a few issues related to dlls that needed to be copied over. |
|
I can't test it on Linux. If anyone can verify... EDIT: Just to clarify. When I refer to "our custom logic", I'm referring to the search that, starting from where the executable/defining assembly is located, looks inside |
|
Adding this for a reference #2596 where the manually copied files are mentioned.. it might be related with the general/future Stride coding on Linux, not necessarily only code-only. |
1b9b87f to
78de4f9
Compare
|
Looks good, as Ethereal mentioned, these changes only changes the priority for certain paths when loading in a library. #2596 would be unaffected as it would require new paths to be probed or binaries to be moved to appropriate paths. |
|
Thanks ! |
This PR modifies the order in which
NativeLibraryHelperinStride.Coretries different strategies for locating the native libraries to load, so it tries first the Stride custom ones, and defers the default .NET strategy as a fallback.PR Details
Some context. I was running the tests in
Stride.Graphics.Testsand found that all tests that made use of fonts, text rendering, etc., were being aborted (not failing) with the following error:After some investigation, I found that
NativeLibraryHelperwas trying to loadfreetype(a native dependency) using the default loading mechanism of .NET, even though that class implements strategies to find native libraries better suited to the custom nature of what Stride needs. The problem was that the tests were sometimes loading the wrong versión of some of our native dependencies.It seems the .NET default strategy (
NativeLibrary.TryLoad) was trying to look forfreetype.dllin the directory where the executable is, the directory where the P/Invoking module is, the current directory, inC:\Windows\System32, etc., and finally, in the paths in the environmentPATHvariable.So, instead of finding our version of
freetypein/runtimes/win-x64, it was loading a different (and incompatible) version it found inC:\Users\Mario\AppData\Local\Microsoft\WinGet\Packages\oschwartz10612.Poppler_Microsoft.Winget.Source_8wekyb3d8bbwe\poppler-25.07.0\Library\bin\freetype.DLL.And not only with
freetype. Instead of loading our version ofd3d3dcompiler_47.dll, it was loadingC:\WINDOWS\SYSTEM32\d3dcompiler_47.DLL(this one is not a problem because they are identical).So, I've restructured and reordered the logic a bit to first look for libraries using our custom logic, and only if none is found, fallback to the default logic. With this change, tests started running and passing as before this problem arised.
I have also:
NativeLibraryLoaderclass.Related Issue
There are several I've found: #1692 #1750
Possibly also #1700 (the incorrectly loaded library does not manifest as crashes sometimes, but as corrupt data or wrong font metrics, etc.)
Types of changes
Checklist