我现在需要在一个form上使用direct3d画一些东西。
在form.show()之后,执行了以下代码PresentParameters presentParams = new PresentParameters();presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;device = new Device(0, DeviceType.Hardware, form, CreateFlags.SoftwareVertexProcessing, presentParams);
现在的问题就是,如果我单独执行这个form,没有任何问题。
但是如果我把这个form作为一个MDI子窗体来显示的话,那么当我把这个子窗体最大化,然后再把父窗体最小化之后,
即使我画面上没有做任何的绘图,都会抛出这个异常。
异常是从Application.Run(new MainForm())中跑出来的。请问这个如何解决?
谢谢。

解决方案 »

  1.   

    异常信息如下:
    未处理 Microsoft.DirectX.Direct3D.DriverInternalErrorException
      Message="应用程序中的错误。"
      Source="Microsoft.DirectX.Direct3D"
      ErrorCode=-2005530585
      ErrorString="D3DERR_DRIVERINTERNALERROR"
      StackTrace:
           在 Microsoft.DirectX.Direct3D.Device.Reset(PresentParameters[] presentationParameters)
           在 Microsoft.DirectX.Direct3D.Device.OnParentResized(Object sender, EventArgs e)
           在 System.Windows.Forms.Control.OnResize(EventArgs e)
           在 System.Windows.Forms.Form.OnResize(EventArgs e)
           在 System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
           在 System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
           在 System.Windows.Forms.Control.UpdateBounds()
           在 System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
           在 System.Windows.Forms.Form.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           在 System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
           在 System.Windows.Forms.Control.DefWndProc(Message& m)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.MdiClient.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           在 System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
           在 System.Windows.Forms.Control.DefWndProc(Message& m)
           在 System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.MdiClient.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.SafeNativeMethods.SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags)
           在 System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
           在 System.Windows.Forms.MdiClient.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
           在 System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.SetBounds(Rectangle bounds, BoundsSpecified specified)
           在 System.Windows.Forms.Layout.DefaultLayout.ApplyCachedBounds(IArrangedElement container)
           在 System.Windows.Forms.Layout.DefaultLayout.xLayout(IArrangedElement container, Boolean measureOnly, Size& preferredSize)
           在 System.Windows.Forms.Layout.DefaultLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
           在 System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
           在 System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
           在 System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
           在 System.Windows.Forms.Form.OnLayout(LayoutEventArgs levent)
           在 System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
           在 System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
           在 System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
           在 System.Windows.Forms.Control.OnResize(EventArgs e)
           在 System.Windows.Forms.Form.OnResize(EventArgs e)
           在 System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
           在 System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
           在 System.Windows.Forms.Control.UpdateBounds()
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
           在 System.Windows.Forms.Form.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.DefFrameProc(IntPtr hWnd, IntPtr hWndClient, Int32 msg, IntPtr wParam, IntPtr lParam)
           在 System.Windows.Forms.Form.DefWndProc(Message& m)
           在 System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
           在 System.Windows.Forms.Form.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.DefFrameProc(IntPtr hWnd, IntPtr hWndClient, Int32 msg, IntPtr wParam, IntPtr lParam)
           在 System.Windows.Forms.Form.DefWndProc(Message& m)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
           在 System.Windows.Forms.Form.WmSysCommand(Message& m)
           在 System.Windows.Forms.Form.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.Run(Form mainForm)
           在 Program.Main()
           在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ThreadHelper.ThreadStart()
      

  2.   

    自己找到一个解决方案,把子窗口的MinimumSize设定为100,100就可以避免这个问题了。