craftworkgames / MonoGame.Extended

Extensions to make MonoGame more awesome
http://www.monogameextended.net/
Other
1.42k stars 323 forks source link

[Gui] Null reference error in monogame spritebatch when calling gui.Draw() #494

Closed lexwebb closed 6 years ago

lexwebb commented 6 years ago

So this is a bit of a wierd one, because it seems like maybe the bug im experiencing is in monogame OR extended, but its source is the Monogame.Extended.Gui package. If this seems like a bug with Monogame instead of extended, please let me know and ill direct my question to the monogame community.

I have a simple UI im creating like so:

ViewportAdapter = new ScalingViewportAdapter(this.GraphicsDevice,
                this.Graphics.PreferredBackBufferWidth, this.Graphics.PreferredBackBufferHeight);

DebugGui = new GuiSystem(ViewportAdapter,
                new GuiSpriteBatchRenderer(GraphicsDevice, () => Matrix.Identity));

Of which im loading some basic panels and textboxes using a modified version of the demo "adventure" theme.

When i attempt to draw this Gui im am getting a NullReferenceException originating at _renderer.End(); call in the draw method of the GuiSystem. I can track this all the way down to the monogame source (DesktopGL) and end up with the following stack trace: https://gist.github.com/lexwebb/78185f41a88d1a0d90f5bc66f6b43c43

Specifically directed to this peice of code

        public Blend ColorSourceBlend
        {
            get { return _targetBlendState[0].ColorSourceBlend; } <=========
            set
            {
                ThrowIfBound();
                _targetBlendState[0].ColorSourceBlend = value;
            }
        }

Where the _targetBlendState array is empty.

I have not been able to follow the source through with enough expertise to work out whats meant to be happening, and why this variable is not filled in the expected way. And thus i am hoping someone here can help.

Please do let me know if any more info is needed.

lexwebb commented 6 years ago

Bug was with my code, was inadvertantly disposing of the spritebatch mid-draw call, closing