Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphicsDevice.PlatformDispose throws System.NullReferenceException #6453

Closed
EnemyArea opened this issue Sep 28, 2018 · 1 comment
Closed
Labels
DirectX DirectX graphics backend

Comments

@EnemyArea
Copy link

After upgrade to monogame 3.7, I've got an NullReferenceException on calling graphicsDevice.Dispose, if monogame is used in a wpf application. Thats because, there is no _swapChain. The line is the first line @ PlatformDispose

"if (_swapChain.IsFullScreen)" <- Here should be checked whether _swapChain is not null

Before 3.7 that error not exists. I have testet on the latest dev branch on Windows 10 Prof.

What version of MonoGame does the bug occur on:

  • MonoGame 3.7

What operating system are you using:

  • Windows 10

What MonoGame platform are you using:

  • WindowsDX
@Jjagg Jjagg added the DirectX DirectX graphics backend label Dec 10, 2018
@craftworkgames
Copy link
Contributor

I ran into the same issue.

The problem should be reproduceable in my MonoGame.WpfCore project.

The exception occurs when the application is shutting down and the GraphicsDevice is disposed on line 18. Although it doesn't seem to happen all the time (maybe some sort of race condition or maybe the debugger is detached before it happens, I'm not sure).

Here's the stack trace I got:

   at SharpDX.DXGI.SwapChain.GetFullscreenState(RawBool& fullscreenRef, Output& targetOut)
   at SharpDX.DXGI.SwapChain.get_IsFullScreen()
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDispose()
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Dispose(Boolean disposing)
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Dispose()
   at SpriteFactory.MonoGameControls.MonoGameGraphicsDeviceService.Dispose()
   at SpriteFactory.MonoGameControls.MonoGameContentControl.CleanUp()
   at SpriteFactory.MonoGameControls.MonoGameContentControl.Finalize()

The problem is quite clear after stepping into the code. In the PlatformDispose method the _swapChain variable is used to change the fullscreen state without checking it for null.

      if (this._swapChain.IsFullScreen)
        this._swapChain.SetFullscreenState((RawBool) false, (Output) null);

But in other parts of the code it is consistently checked for null. For example in the CreateSizeDependentResources method a very similar bit of code exists.

          if (this._swapChain != null)
          {
            flag = this._swapChain.IsFullScreen;
            this._swapChain.SetFullscreenState((RawBool) false, (Output) null);
            this._swapChain.Dispose();
          }

Jjagg added a commit that referenced this issue Aug 21, 2019
Fix issue #6453 - SwapChain is null in GraphicsDevice.PlatformDispose
@Jjagg Jjagg closed this as completed Aug 21, 2019
kimimaru4000 pushed a commit to kimimaru4000/MonoGame that referenced this issue Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DirectX DirectX graphics backend
Projects
None yet
Development

No branches or pull requests

2 participants