Closed philstopford closed 5 years ago
Strange, it's working on my end. I see mention of "WinFormsControl", so I assume this is the WPF version, but whether I run it with Vulkan, D3D, or OpenGL, I can switch back and forth between those tabs just fine.
What kind of system are you running this on? I've got Windows 10, version 1903, and an AMD RX 460 with the Adrenalin 19.6.3 drivers.
GeForce GTX 1060, latest available drivers (436.30). Win 10 Pro 1903
It's the Vulkan backend that seems to object.
Hmm. I do think it's odd that it's hitting that init function a second time, I guess the Control.Loaded event is being raised every time you switch to the tab on your system. Maybe a graphics driver difference.
What if you replace the InitializeOtherApi method with this:
public void InitializeOtherApi()
{
Control.Loaded += OneTimeControlInit;
}
private void OneTimeControlInit(object sender, System.Windows.RoutedEventArgs e)
{
// To embed Veldrid in an Eto control, all these platform-specific
// versions of InitializeOtherApi use the technique outlined here:
//
// https://github.com/mellinoe/veldrid/issues/155
//
var source = SwapchainSource.CreateWin32(
WinFormsControl.Handle,
Marshal.GetHINSTANCE(typeof(VeldridSurface).Module));
Widget.Swapchain = Widget.GraphicsDevice.ResourceFactory.CreateSwapchain(
new SwapchainDescription(
source,
(uint)RenderWidth,
(uint)RenderHeight,
PixelFormat.R32_Float,
false));
Control.Loaded -= OneTimeControlInit;
Callback.OnVeldridInitialized(Widget, EventArgs.Empty);
}
That way the handler removes itself after the first initialization and won't be called again. It seems to keep working on my computer, at least.
That seems to make things happier.
Take the existing MainForm() constructor and make it :
` public MainForm(GraphicsBackend backend, string executableDirectory, string shaderSubdirectory) { InitializeComponent();
`
Change to the second tab and then back to the first. A crash will occur:
{"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}'
in the SwapChain call below:
` public void InitializeOtherApi() { Control.Loaded += (sender, e) => { // To embed Veldrid in an Eto control, all these platform-specific // versions of InitializeOtherApi use the technique outlined here: // // https://github.com/mellinoe/veldrid/issues/155 // var source = SwapchainSource.CreateWin32( WinFormsControl.Handle, Marshal.GetHINSTANCE(typeof(VeldridSurface).Module));
`