Multi-Monitor Problem

loki of mute's picture

Hi there!

I noticed (not only with Nuclex XNA games, but with all/most XNA demos that do more than just draw an untextured triangle) that XNA or our implementations have a severe problem with multiple monitors. Just try this: run an XNA game on your PC on your main screen, in a window. Then drag it all the way over to your second monitor (assuming you have one ;-).

For some reason, XNA is incorrectly releasing content and crashes.
In my own code, I've been trying to get around this, but with no success. Anyone has got a clue where the problem lies?
I'm starting to believe (completely unbased however) that it's not us that call the XNA framework somehow incorrectly, but that the problem lies withing XNA itself.

It's a really nasty problem, because it means that our XNA experiments have a weak crashy point.
In games, this is not such a big problem, but once you start developing tools with XNA, you can't expect the user to never move a window to another monitor, no?

anyone who has noticed this problem too, or knows a genius solution to it?

kind regards,
loki

Nemo Krad's picture

I had this issue and got

I had this issue and got around it like this.

Wired two events to the main game object like this:

Window.ClientSizeChanged += new EventHandler(Resize);
Window.ScreenDeviceNameChanged += new EventHandler(DeviceChanged);

And wrote these methods to go with them:

public void Resize(object sender, EventArgs e)
{
Camera.myViewport.Width = Window.ClientBounds.Width;
Camera.myViewport.Height = Window.ClientBounds.Height;
}
void DeviceChanged(object sender, EventArgs e)
{
Camera.myViewport = graphics.GraphicsDevice.Viewport;
Camera.myViewport.MinDepth = .5f;
Camera.myViewport.MaxDepth = 1000f;
}

Hope this helps.
http://randomchaosuk.blogspot.com/

Cygon's picture

Didn't have any issues...

I'm using a multi-mon system at home and, just to see whether performance degrades, I dragged my XNA windows onto the secondary screen on several occassions. I didn't have any crashes at all, XNA silently created a new GraphicsDevice and the GraphicsDeviceManager did the usual UnloadGraphicsContent(true) and LoadGraphicsContent(true) cycle.

Are you by any chance using RenderTargets, dynamic vertex/index buffers or some other resource that requires manual resource management? That would be my first guess, because, as soon as you forget just a single manually managed resource, the GraphicsDevice cannot be reset anymore and when a new GraphicsDevice is created, just accessing that resource will cause an Exception.

Nemo Krad's picture

In my case..

The issue was happening because the viewport my camera was using gets destroyed and so my wired events reset my cameras view port. At least that's my best guess as to why I got the issue. :)

http://randomchaosuk.blogspot.com/

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <br> <a> <em> <strong> <u> <i> <b> <cite> <blockcode> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <pre> <span>
  • You can highlight code with any of the following tags: <blockcode>

More information about formatting options