SDLGame window Null reference at startup

I have just tried to update the MonoGame dlls used in my game to the current git copy. When starting up it now crashes with the following exception. Previously the version I had was using OpenTK which I assume was replaced with SDL.

Message: Object reference not set to an instance of an object.

Stack Trace:
at Microsoft.Xna.Framework.SdlGameWindow.ClientResize(Int32 width, Int32 height)
at Microsoft.Xna.Framework.SdlGamePlatform.SdlRunLoop()
at Microsoft.Xna.Framework.SdlGamePlatform.BeforeInitialize()
at Microsoft.Xna.Framework.Game.DoInitialize()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at Microsoft.Xna.Framework.Game.Run()

Im using Windows 7 with VS2015 and trying to target DesktopGL profile although i can’t see that specific dll project so Im using WindowsGL instead.

Thanks

You need to add some additional dependencies. I’d except a different exception though, like a missing DLL. Easiest way to get set up for now is to install the latest develop version from the Downloads page, create a new DesktopGL project and copy over the dependencies.

Hi Jjagg
I downloaded the latest installer of dev build, the project template install checkboxes were all disabled so I had to pull a git copy. Then all the VS templates will not work, i get the following error:

Project is not support by this installation, Missing subtype {BC8A1FFA-BEE3-4634-8014-F334798102B3}

Which indicates a Windows Store App so they are only supported by Windows 8+ according to some google posts i read. The only one that worked was VS2010, why is desktop gl removed in all the later VS templates and only windows app store and phone templates?

So I checked all the dependencies but still i get the same error, not sure what else to look at.

Progress in finding out what the issue is, if i change the following line in my constructor to FALSE then the game starts.

Window.AllowUserResizing = true;

Ah, it might be a bug in that case. Try moving that line to your initialization.

Yep that has fixed it, moved it to the Initialize method and its happy now. Still a few small issues to fix after the upgrade but not as many as I expected considering the change from OpenTK to SLD.

Thanks Jjagg :slight_smile:

1 Like

You’re welcome!

The problem is that the SDL DLL’s are loaded at runtime after the Game constructor, so trying to set stuff in the constructor or in static initializers of your Game1 class (or other classes you use in the constructor) won’t be able to access SDL functionality. We can fix the constructor case by loading the SDL library in the Game constructor probably, but not the static initializers. I wonder if there’s a better solution here…

Actually I can’t reproduce your issue, so I’m wrong in my previous post…
EDIT: Just checked the source code and the initialization of the SDL window happens in the Game constructor, so not sure why you ran into this issue @Kryten

Window.AllowUserResizing = true;

That got broken about a month or two ago i think around second week of nov or dec. i didn’t check into it too deeply but i think someone hard coded the value to false at that time.
Like it was stuck on false you couldn’t set it to true.

So apparently its not quite fixed or your maybe on a older version. I could probably find the issue number if you like.

There are a bunch of issues with window and GraphicsDeviceManager stuff. I have an open pull request to resolve I hope most of them, but it’s almost DX exclusive since DesktopGL uses a legacy GraphicsDeviceManager. The reason for that is we don’t have tests running for DesktopGL because of some complications so the maintainers don’t want to meege in big changes like switching to the new GraphicsDeviceManager. It’ll all get better soon though!

But I tested AllowUserResizing a few days ago and that seems to be working for both DesktopGL and DirectX on latest develop