Fix FileDialogManager not doing DLL mapping properly in sandbox, and FileDialogManager hard crash on multiple dialogs (#1505)

This commit is contained in:
20kdc
2021-01-14 12:43:39 +00:00
committed by GitHub
parent c4062bcae9
commit 2eeb21431b
3 changed files with 28 additions and 63 deletions

View File

@@ -17,6 +17,7 @@ namespace OpenToolkit.GraphicsLibraryFramework
// On net472, we rely on Mono's DllMap for this. See the .dll.config file.
NativeLibrary.SetDllImportResolver(typeof(GLFWNative).Assembly, (name, assembly, path) =>
{
// Please keep in sync with what Robust.Shared/DllMapHelper.cs does.
if (name != "glfw3.dll")
{
return IntPtr.Zero;

View File

@@ -179,7 +179,17 @@ namespace Robust.Client.UserInterface
return tcs.Task;
#else
// Luckily, GTK Linux and COM Windows are both happily threaded. Yay!
return Task.Run(action);
// * Actual attempts to have multiple file dialogs up at the same time, and the resulting crashes,
// have shown that at least for GTK+ (Linux), just because it can handle being on any thread doesn't mean it handle being on two at the same time.
// Testing system was Ubuntu 20.04.
// COM on Windows might handle this, but honestly, who exactly wants to risk it?
// In particular this could very well be an swnfd issue.
return Task.Run(() =>
{
lock (this) {
return action();
}
});
#endif
}

View File

@@ -14,45 +14,7 @@ namespace Robust.Shared
// On .NET Framework this doesn't need to run because:
// On Windows, the DLL names should check out correctly to just work.
// On Linux/macOS, Mono's DllMap handles it for us.
#if NETCOREAPP
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// DLL names should line up on Windows by default.
// So a hook won't do anything.
return;
}
NativeLibrary.SetDllImportResolver(assembly, (name, _, __) =>
{
if (name == $"{baseName}.dll")
{
var assemblyDir = Path.GetDirectoryName(assembly.Location);
if (assemblyDir == null)
{
return IntPtr.Zero;
}
string libName;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
libName = $"lib{baseName}.so";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
libName = $"lib{baseName}.dylib";
}
else
{
throw new NotSupportedException();
}
return NativeLibrary.Load(Path.Combine(assemblyDir, libName));
}
return IntPtr.Zero;
});
#endif
RegisterExplicitMap(assembly, $"{baseName}.dll", $"lib{baseName}.so", $"lib{baseName}.dylib");
}
[Conditional("NETCOREAPP")]
@@ -62,32 +24,24 @@ namespace Robust.Shared
// On Windows, the DLL names should check out correctly to just work.
// On Linux/macOS, Mono's DllMap handles it for us.
#if NETCOREAPP
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
NativeLibrary.SetDllImportResolver(assembly, (name, assembly, path) =>
{
// DLL names should line up on Windows by default.
// So a hook won't do anything.
return;
}
NativeLibrary.SetDllImportResolver(assembly, (name, _, __) =>
{
if (name == baseName)
// Please keep in sync with what GLFWNative does.
// This particular API is only really used by the MIDI instruments stuff in SS14 right now,
// which means when it breaks people don't notice or report.
if (name != baseName)
{
string libName;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
libName = linuxName;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
libName = macName;
}
else
{
throw new NotSupportedException();
}
return IntPtr.Zero;
}
return NativeLibrary.Load(libName);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return NativeLibrary.Load(linuxName, assembly, path);
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return NativeLibrary.Load(macName, assembly, path);
}
return IntPtr.Zero;