This project is read-only.

Issue on WinForm hosting

Feb 26, 2010 at 11:20 PM
Edited Feb 26, 2010 at 11:22 PM

Hi StatusUnknown,

I'm working on an Editor and I'm using the Winform implementation to display a 3d scene where I'll be able to edit my scenes.

It works perfectly when you are using the Tutorials but there is a bug if you override SetupGraphicsDeviceManager(GraphicsDeviceManager, ref Presentation) which I do by inheriting Xen.Application.

Browsing the source code,  I found the following portion on 1.7.1:


internal XNAWinFormsHostAppWrapper(XNALogic logic, Application parent, WinFormsHostControl host)


parent.SetWindowSizeAndFormat(width, height, format, DepthFormat.Depth24Stencil8);

parent.SetupGraphicsDeviceManager(null, ref presentation);

formsDeviceService.CreateDevice(presentation, host);
host.SetApplication(parent, this, formsDeviceService);

host.BeginInvoke((EventHandler)delegate { parent.SetGraphicsDevice(GraphicsDevice); logic.Initialise(); logic.LoadContent(); }); }


As you can see, the call to SetupGraphicsDeviceManager provides a null GraphicsDeviceManager.

I'm filling up a bug ticket in Codeplex for this but could you be so kind and share some clues on how I could handle this? (I really need to use the SetupGraphicsDeviceManager override)


Note that if I try to create an instance of the GraphicsDeviceManager myself, I get an exception stating that it is already created.
So it seems that I'm missing something somewhere as it seems that Xen creates an instance of the GraphicsDeviceManager but I can't get it.

Thanks for your help.


Mar 11, 2010 at 11:59 PM

Hi Philippe, Sorry I haven't replied quickly..

I based the WinForms code on the official XNA sample (which is apparently best practice). It specifically doesn't use the GraphicsDeviceManager, because the GDM is (apparently) specific to Xna Game code. The sample itself doesn't have a GDM.

What specific features of the GDM do you need? If you need to set the back buffer format, then I'd suggest simply using a render target intermediate (you won't be able to set it otherwise).

Unfortunately I'm not aware of any way to get around this...


Mar 12, 2010 at 9:44 AM

Hi StatusUnknown,

Thanks for your answer. I solved my issue by not using the SetupGraphicsDeviceManager protected method for this project but I wanted to raise this still as a bug in the API because it breaks the Xen API consistency as you can't override SetupGraphicsDeviceManager and use the "graphics" property as you would in a standard Xen usage.

Therefore, you may potentially want to add a compiler instruction when using WinForms hosting and some additional comments to this method signature so that Xen users know they cannot override SetupGraphicsDeviceManager and use its inner arguments (graphics actually) when using Xen with the built in Winforms hosting controls.