Changing screen may cause disposed exceptions


Dragging a Neoforce Application window between 3 or more screens causes one of the following exceptions;
  1. ObjectDisposedException in the following locations;
    • Renderer.cs - Method: Renderer.Begin (Line 162 or 166) ObjectName: GraphicsDevice
    • Control.cs - Method: Control.PrepareTexture (Line 1495) ObjectName: RenderTarget2D
  2. InvalidOperationException in Application.cs (Line 401)
    • A previous Draw call threw an unhandled exception.
    • Inner Exception: {"Cannot access a disposed object.\r\nObject name: 'GraphicsDevice'."}
Can be reproduced in r31568, using "Central" demo application (100% with SystemBorder=true, very rarely when SystemBorder=false).

file attachments


grimston wrote Apr 9, 2013 at 6:26 AM

Hi dharcode,

By 3 Screens, do you mean, pushing the app window across, 3 monitors?

I am unable to test issues, with more then a single screen. I could probably test two monitors, but not three, as I use a laptop.

Does the exception occur, when parts of the window, should be entering a new screen? or just randomly while using 3 screens?

wrote Apr 9, 2013 at 7:49 AM

dharcode wrote Apr 9, 2013 at 7:49 AM

Hi Grimstone,

Yes, three monitors.

It happens when the horizontal mid-line of the game/application crosses between the 2nd and 3rd monitor. (100% reproduction rate with SystemBorder = true, <10% rate when SystemBorder = false)

I did more testing and I found a way to reproduce all of the symptoms with two monitors. In particular when I drag the game/application horizontal mid-line from monitor 1 to monitor 2 and then back again in a continuous manner then it happens. (Same rates regarding SystemBorder)

I've attached a video demonstrating the issue. If you cannot view the video, and are interested in seeing it, let me know and I'll upload it to youtube.

Many thanks,

P.S. I love this library.

dharcode wrote Apr 30, 2013 at 8:41 PM


I've discovered that this is caused by the 'immediate' disposing of a newly created Manager Render Target. (Which happens when there are multiple invocations of the Graphics.DeviceReset event)

I've implemented a fix, please see on github. http://github.com/dharco/Neoforce/commit/b02b29122b569b478e1386ac0e961f1a0d6cd8e2