0

I'm using Managed DirectX/C#/WinForms for some graphics and video rendering.

I'm using my own SwapChain and setting Device.IsUsingEventHandlers = true, otherwise my for OnDeviceLost and OnDeviceReset event handlers don't get called (why?)

So, when the user clicks to minimize the form, I'm getting a call to OnResize(), which I override. The this.ClientSize is (0, 0) on that minimize.

In OnResize() call I set flags to skip Draw() function.

I get OnDeviceLost event handler call, where I free resources.

After that the code crashes on "automatic/implicit" device.Reset() call, which would've normally be followed by a call to OnDeviceReset() even handler I set for my device.

I wasn't able to find how this minimize event should be handled to avoid a crash on implicit device.Reset(). Need help with this, pls.

Do I need to dispose the device and destroy the DirectShow graph when it's present (I don't always render video) on minimize? Or is there a standard way of handling minimize event? The code crashes even when I don't create DirectShow graph, just rendering a few lines here and there, no video, so the crash is not DirectShow related, it seems.

A crash call stack looks like this: Error in the application.

Microsoft.DirectX.Direct3D
   at Microsoft.DirectX.Direct3D.Device.Reset(PresentParameters[] presentationParameters)
   at Microsoft.DirectX.Direct3D.Device.OnParentResized(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
   at WeifenLuo.WinFormsUI.Docking.DockContent.OnSizeChanged(EventArgs e)
   at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
   at System.Windows.Forms.Control.UpdateBounds()
   at System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Jim
  • 25
  • 2
  • 8
  • Keep in mind that the Managed DirectX assemblies are designed for .NET 1.1 and haven't been updated an ages. They are deprecated and you should consider using something more modern like [SharpDX](http://sharpdx.org/). See [DirectX and .NET](https://blogs.msdn.microsoft.com/chuckw/2010/12/09/directx-and-net/) – Chuck Walbourn Jul 20 '17 at 07:38
  • Thank you for your feedback. We eventually plan to move to the WPF and... whatever replaces MDX. I just wasn't sure how to solve the present isolated problem. – Jim Jul 20 '17 at 10:41

0 Answers0