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

Exceptions while trying to use Veldrid to make a VST UI #513

Open
Ideae opened this issue Jul 31, 2023 · 2 comments
Open

Exceptions while trying to use Veldrid to make a VST UI #513

Ideae opened this issue Jul 31, 2023 · 2 comments

Comments

@Ideae
Copy link

Ideae commented Jul 31, 2023

I'm trying to use Veldrid with ImGUI and NPlug to make a UI for a VST plugin. Veldrid works fine when I build the ImGui.NET sample projects, but when I try to use it with NPlug to run inside a vsthost, I get a bunch of exceptions. The vsthost provides a window handle to an HWND window, so I use that to create a new Sdl2Window. But when I try to use that to create a new Graphics Device (calling VeldridStartup.CreateGraphicsDevice), I get an exception.

Code:

public static void StartUILoop(nint windowHandle) { _window = new Sdl2Window(windowHandle, false); _gd = VeldridStartup.CreateGraphicsDevice(_window, new GraphicsDeviceOptions(true, null, true, ResourceBindingModel.Improved, true, true));

Exception 1:

Caught exception: System.PlatformNotSupportedException: Cannot create a SwapchainSource for Unknown. 11:38:13:758 at Veldrid.StartupUtilities.VeldridStartup.GetSwapchainSource(Sdl2Window) + 0x393 11:38:13:758 at Veldrid.StartupUtilities.VeldridStartup.CreateDefaultD3D11GraphicsDevice(GraphicsDeviceOptions, Sdl2Window) + 0x46 11:38:13:758 at Veldrid.StartupUtilities.VeldridStartup.CreateGraphicsDevice(Sdl2Window, GraphicsDeviceOptions, GraphicsBackend) + 0x8a 11:38:13:758 at Veldrid.StartupUtilities.VeldridStartup.CreateGraphicsDevice(Sdl2Window, GraphicsDeviceOptions) + 0x68 11:38:13:758 at NPlug.TestDelay.UILoop.StartUILoop(IntPtr) + 0x117

I'm not sure why that is happening but I think it could be the root of the problem. I actually used a hack to get around it because I realized that the window had the value 'Unknown' for the platform, so I manually set it to 'Windows' inside the Veldrid source code. But then I got more exceptions when calling the same function. This time it was deeper in the SharpDX code:

Exception 2:

Caught exception: System.MissingMethodException: No parameterless constructor defined for type 'SharpDX.DXGI.Device'. 17:26:42:030 at System.ActivatorImplementation.CreateInstance(Type, BindingFlags, Binder, Object[], CultureInfo, Object[]) + 0x3e9 17:26:42:030 at System.Reflection.Runtime.General.ReflectionCoreCallbacksImplementation.ActivatorCreateInstance(Type, BindingFlags, Binder, Object[], CultureInfo, Object[]) + 0x47 17:26:42:030 at System.Activator.CreateInstance(Type, BindingFlags, Binder, Object[], CultureInfo, Object[]) + 0x6b 17:26:42:030 at System.Activator.CreateInstance(Type, Object[]) + 0x3c 17:26:42:030 at SharpDX.CppObject.FromPointer[T](IntPtr) + 0xb2 17:26:42:030 at SharpDX.ComObject.QueryInterface[T]() + 0xb9 17:26:42:030 at Veldrid.D3D11.D3D11GraphicsDevice..ctor(D3D11DeviceOptions, Nullable1) + 0x3f8 17:26:42:030 at Veldrid.D3D11.D3D11GraphicsDevice..ctor(GraphicsDeviceOptions, D3D11DeviceOptions, Nullable1) + 0xaf 17:26:42:030 at Veldrid.GraphicsDevice.CreateD3D11(GraphicsDeviceOptions, SwapchainDescription) + 0xdc 17:26:42:030 at Veldrid.StartupUtilities.VeldridStartup.CreateDefaultD3D11GraphicsDevice(GraphicsDeviceOptions, Sdl2Window) + 0xe7 17:26:42:030 at Veldrid.StartupUtilities.VeldridStartup.CreateGraphicsDevice(Sdl2Window, GraphicsDeviceOptions, GraphicsBackend) + 0x92 17:26:42:030 at Veldrid.StartupUtilities.VeldridStartup.CreateGraphicsDevice(Sdl2Window, GraphicsDeviceOptions) + 0x68 17:26:42:030 at NPlug.TestDelay.UILoop.StartUILoop(IntPtr) + 0x114

I am using Veldrid 4.8.0 because that is what is used in the ImGui.NET samples. When I upgraded to 4.9.0 I got different issues (DXGI ERROR). My assumption is that Veldrid is having trouble running inside the vsthost context, but I'm not sure how to fix that. Any help would be appreciated.

@mellinoe
Copy link
Collaborator

mellinoe commented Aug 5, 2023

I'm not familiar with NPlug, but my guess is that the window handle it's giving you is not the same kind of window handle that SDL2/VeldridStartup is expecting and this is causing issues. You will most likely have to figure out what type of window handle it gives you and create a Swapchain directly from that. My guess is that you're actually getting a native Win32 HWND out of NPlug, which would mean you need to use something like SwapchainSource.CreateWin32(). It may be possible to get an SDL2 window by having it wrap the existing HWND and continue your existing path, but I'm not sure how to do that off the top of my head.

@mellinoe
Copy link
Collaborator

mellinoe commented Aug 5, 2023

Actually, now that I look closer:

The vsthost provides a window handle to an HWND window, so I use that to create a new Sdl2Window.

That should work, since the Sdl2Window constructor calls SDL_CreateWindowFrom which expects an HWND. Not sure why you had to hack around the "Unknown" swapchain type, that's more than a little suspicious. It implies the SDL window isn't properly returning its type, which means the SDL window itself could be messed up or improperly initialized.

Using 4.9 is probably a better starting point since SharpDX was completely replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants