Merge branch 'editor_module_lookup_fix' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-editor_module_lookup_fix

This commit is contained in:
Wojtek Figat
2023-09-18 15:16:07 +02:00
4 changed files with 14 additions and 7 deletions

View File

@@ -184,7 +184,7 @@ namespace FlaxEngine.Interop
{
string moduleName = Marshal.PtrToStringAnsi(moduleNamePtr);
string modulePath = Marshal.PtrToStringAnsi(modulePathPtr);
nativeLibraryPaths[moduleName] = modulePath;
libraryPaths[moduleName] = modulePath;
}
[UnmanagedCallersOnly]
@@ -909,7 +909,7 @@ namespace FlaxEngine.Interop
loadedNativeLibraries.Remove(nativeLibraryName);
}
if (nativeLibraryName != null)
nativeLibraryPaths.Remove(nativeLibraryName);
libraryPaths.Remove(nativeLibraryName);
}
[UnmanagedCallersOnly]

View File

@@ -50,7 +50,7 @@ namespace FlaxEngine.Interop
private static Dictionary<Type, int> _typeSizeCache = new();
private static Dictionary<string, IntPtr> loadedNativeLibraries = new();
internal static Dictionary<string, string> nativeLibraryPaths = new();
internal static Dictionary<string, string> libraryPaths = new();
private static Dictionary<Assembly, string> assemblyOwnedNativeLibraries = new();
internal static AssemblyLoadContext scriptingAssemblyLoadContext;
@@ -59,7 +59,7 @@ namespace FlaxEngine.Interop
{
if (!loadedNativeLibraries.TryGetValue(libraryName, out IntPtr nativeLibrary))
{
if (!nativeLibraryPaths.TryGetValue(libraryName, out var nativeLibraryPath))
if (!libraryPaths.TryGetValue(libraryName, out var nativeLibraryPath))
nativeLibraryPath = libraryName;
nativeLibrary = NativeLibrary.Load(nativeLibraryPath, assembly, dllImportSearchPath);
@@ -101,9 +101,9 @@ namespace FlaxEngine.Interop
private static Assembly OnScriptingAssemblyLoadContextResolving(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName)
{
// FIXME: There should be a better way to resolve the path to EditorTargetPath where the dependencies are stored
foreach (string nativeLibraryPath in nativeLibraryPaths.Values)
foreach (string libraryPath in libraryPaths.Values)
{
string editorTargetPath = Path.GetDirectoryName(nativeLibraryPath);
string editorTargetPath = Path.GetDirectoryName(libraryPath);
var assemblyPath = Path.Combine(editorTargetPath, assemblyName.Name + ".dll");
if (File.Exists(assemblyPath))

View File

@@ -719,6 +719,13 @@ bool MAssembly::LoadImage(const String& assemblyPath, const StringView& nativePa
StringAnsi nativeName = _name.EndsWith(".CSharp") ? StringAnsi(_name.Get(), _name.Length() - 7) : StringAnsi(_name);
RegisterNativeLibrary(nativeName.Get(), StringAnsi(nativePath).Get());
}
#if USE_EDITOR
// Register the editor module location for Assembly resolver
else
{
RegisterNativeLibrary(_name.Get(), StringAnsi(assemblyPath).Get());
}
#endif
_hasCachedClasses = false;
_assemblyPath = assemblyPath;

View File

@@ -19,7 +19,7 @@ namespace FlaxEngine.Tests
{
var result = 0;
var libraryName = "FlaxEngine";
var library = NativeLibrary.Load(Interop.NativeInterop.nativeLibraryPaths[libraryName]);
var library = NativeLibrary.Load(Interop.NativeInterop.libraryPaths[libraryName]);
if (library == IntPtr.Zero)
return -1;
var types = typeof(FlaxEngine.Object).Assembly.GetTypes();