Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is creating a GraphicsDevice causing an "unexpected error" on instantiation?
    primarykey
    data
    text
    <p>I'm trying to embed a bare bones XNA application in a Winforms MDI application, and I seem to be having issues. I am following the example of <a href="http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_1" rel="nofollow">http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_1</a> and I'm not sure what I'm doing wrong.</p> <p>In my MDI parent I am instantiating the rendering form via:</p> <pre><code> private void MainForm_Load(object sender, EventArgs e) { var render = new RenderForm(); render.MdiParent = this; render.Show(); } </code></pre> <p>The code for my rendering form is:</p> <pre><code>public class RenderForm : Form { private XnaRenderer _renderer; protected override void OnCreateControl() { if (!DesignMode) _renderer = new XnaRenderer(Handle, ClientSize.Width, ClientSize.Height); base.OnCreateControl(); } protected override void OnPaint(PaintEventArgs e) { _renderer.RenderScene(null); } } </code></pre> <p>So when the form is created, it attempts to create an instance of my <code>XnaRenderer</code> class. <code>ClientSize.Width</code> is 284 and <code>ClientSize.Height</code> is 261, and the <code>Handle</code> looks to be valid. The constructor's code is:</p> <pre><code> public XnaRenderer(IntPtr windowHandle, int width, int height) { _graphicsService = new GraphicsDeviceService(windowHandle, width, height); SetViewport(width, height); } </code></pre> <p>The <code>GraphicsDeviceService</code> class is essentially the same as the one from the example code, but it's made to not be a singleton. The code for the constructor is:</p> <pre><code> public GraphicsDeviceService(IntPtr windowHandle, int width, int height) { _presentationParams = new PresentationParameters { BackBufferFormat = SurfaceFormat.Color, BackBufferHeight = Math.Max(height, 1), BackBufferWidth = Math.Max(width, 1), DepthStencilFormat = DepthFormat.Depth24, DeviceWindowHandle = windowHandle, PresentationInterval = PresentInterval.Immediate }; _graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, _presentationParams); } </code></pre> <p>However, when the <code>GraphicsDevice</code> object is instantiated I get the following <code>InvalidOperationException</code>: </p> <blockquote> <p>An unexpected error has occurred.</p> </blockquote> <p>There is no more to the exception's message and no inner exception, making this pretty hard to debug without a lot of XNA knowledge.</p> <p>Does anyone see something I am doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload