最小限の XNA アプリケーションを Winforms MDI アプリケーションに埋め込もうとしていますが、問題が発生しているようです。http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_1の例に従っていますが、何が間違っているのかわかりません。
私の MDI の親では、次の方法でレンダリング フォームをインスタンス化しています。
private void MainForm_Load(object sender, EventArgs e)
{
var render = new RenderForm();
render.MdiParent = this;
render.Show();
}
私のレンダリングフォームのコードは次のとおりです。
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);
}
}
そのため、フォームが作成されると、XnaRenderer
クラスのインスタンスを作成しようとします。 ClientSize.Width
は 284 でClientSize.Height
261 で、Handle
見た目は有効です。コンストラクターのコードは次のとおりです。
public XnaRenderer(IntPtr windowHandle, int width, int height)
{
_graphicsService = new GraphicsDeviceService(windowHandle, width, height);
SetViewport(width, height);
}
クラスは基本的にGraphicsDeviceService
コード例と同じですが、シングルトンにならないように作られています。コンストラクターのコードは次のとおりです。
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);
}
ただし、GraphicsDevice
オブジェクトがインスタンス化されると、次のようになりますInvalidOperationException
。
予期しないエラーが発生しました。
例外のメッセージと内部例外はこれ以上ないため、XNA の知識がなければこれをデバッグするのはかなり困難です。
誰かが私が間違っていることを見ていますか?