1
\$\begingroup\$

I switched my Project from XNA 4 to MonoGame 2.5.1. The port went somewhat unproblematic but I am stumpled across a problem i can't resolve. For your interest, the code worked on XNA:

When I am drawing a spritebatch with a basicEffect I get an ArgumentNullException on calling the End() method. This is the simplified draw call

// polyEffTest is defined somewhere else, not in the draw function
polyEffTest = new PolygonBasicEffect(gd);  

// the simplified draw call
sbTest.Begin(
  SpriteSortMode.BackToFront,
  BlendState.AlphaBlend,
  SamplerState.LinearClamp,
  DepthStencilState.Default,
  GraphicsDevice.RasterizerState,
  polyEffTest,
  Matrix.CreateTranslation(offX, offY, 0f)
);

// draw something [...]

sbTest.End() // <- End-call causes Exception

when I replace polyEffTest with NULL in sbTest.Begin I won't get the ArgumentNullException but nothing gets drawed either (obvious). So I guess it has to do something with the BasicEffect

Here is the stacktrace

>   at OpenTK.Graphics.ES11.GL.GetError () [0x00000] in <filename
> unknown>:0    at OpenTK.Graphics.ES11.ErrorHelper.ResetErrors ()
> [0x00000] in <filename unknown>:0    at
> OpenTK.Graphics.ES11.ErrorHelper..ctor (IGraphicsContext context)
> [0x00000] in <filename unknown>:0    at
> OpenTK.Graphics.ES11.GL.Viewport (Int32 x, Int32 y, Int32 width, Int32
> height) [0x00000] in <filename unknown>:0    at
> Microsoft.Xna.Framework.Graphics.GLStateManager.Viewport (Rectangle
> viewport) [0x00000] in <filename unknown>:0    at
> Microsoft.Xna.Framework.Graphics.BasicEffect.Apply () [0x00000] in
> <filename unknown>:0    at
> Microsoft.Xna.Framework.Graphics.SpriteBatch.End () [0x00000] in
> <filename unknown>:0    at RustyMoon.Game1.Draw
> (Microsoft.Xna.Framework.GameTime gameTime) [0x001b1] in
> /home/mereddyn/projects/c#/RMoonMono/RMoonMono/Game1.cs:306    at
> Microsoft.Xna.Framework.Game.DoDraw (Microsoft.Xna.Framework.GameTime
> gameTime) [0x00000] in <filename unknown>:0    at
> Microsoft.Xna.Framework.GameWindow.OnRenderFrame (System.Object
> sender, OpenTK.FrameEventArgs e) [0x00000] in <filename unknown>:0   
> at OpenTK.GameWindow.OnRenderFrame (OpenTK.FrameEventArgs e) [0x00000]
> in <filename unknown>:0    at OpenTK.GameWindow.OnRenderFrameInternal
> (OpenTK.FrameEventArgs e) [0x00000] in <filename unknown>:0    at
> OpenTK.GameWindow.RaiseRenderFrame (System.Diagnostics.Stopwatch
> render_watch, System.Double& next_render, OpenTK.FrameEventArgs
> render_args) [0x00000] in <filename unknown>:0    at
> OpenTK.GameWindow.DispatchUpdateAndRenderFrame (System.Object sender,
> System.EventArgs e) [0x00000] in <filename unknown>:0    at
> OpenTK.GameWindow.Run (Double updates_per_second, Double
> frames_per_second) [0x00000] in <filename unknown>:0    at
> OpenTK.GameWindow.Run (Double updateRate) [0x00000] in <filename
> unknown>:0    at Microsoft.Xna.Framework.GameWindow.Run (Double
> updateRate) [0x00000] in <filename unknown>:0    at
> Microsoft.Xna.Framework.LinuxGamePlatform.RunLoop () [0x00000] in
> <filename unknown>:0    at Microsoft.Xna.Framework.Game.Run
> (GameRunBehavior runBehavior) [0x00000] in <filename unknown>:0    at
> Microsoft.Xna.Framework.Game.Run () [0x00000] in <filename unknown>:0 
> at RustyMoon.Program.Main () [0x00010] in
> /home/mereddyn/projects/c#/RMoonMono/RMoonMono/Program.cs:20

I am using MonoGame 2.5.1 on Ubuntu 14.04 with MonoDevelop. The polyEffTest is defined like that:

public class PolygonBasicEffect : BasicEffect
{
    public PolygonBasicEffect(GraphicsDevice graphicsDevice)
        : base(graphicsDevice)
    {
        this.VertexColorEnabled = true;
        this.TextureEnabled = true;
        this.Projection = Matrix.CreateOrthographicOffCenter(
            0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 0, 1
        );
    }

    public PolygonBasicEffect(BasicEffect effect)
        : base(effect)
    {
    }

    public BasicEffect Clone()
    {
        return new PolygonBasicEffect(this);
    }
}

Even if I am calling the End call imediatly after the Begin i get the Exception. I even get the exception if I am replacing polyEffTest with a new BasicEffect()

Update

I did some testing on a different machine. I downloaded the same Mono Version 2.5.1 and tried it on a Windows 7 System with Visual Studio. It works. I will try it with a different linux machine the end of the day. In addition, I stumpled across something. I guess there is an issue with unsafe code within MonoDevelop on my main system. But I can't tell you anything until tomorrow.

\$\endgroup\$
8
  • 2
    \$\begingroup\$ Have you tried downloading the Monogame source and referencing that instead of the DLLs? \$\endgroup\$
    – ashes999
    Apr 26, 2014 at 23:12
  • \$\begingroup\$ yes, and even with an empty project with just the three calls, new BasicEffect, Begin, End. As soon as the BasicEffect comes in, crash. I will try it on a dif. machine tomorrow \$\endgroup\$
    – Ello
    Apr 27, 2014 at 18:02
  • \$\begingroup\$ Are you able to look at the exception / inner exception and get any useful details? \$\endgroup\$
    – ashes999
    Apr 28, 2014 at 2:04
  • \$\begingroup\$ the expception is "ArgumentNullException..." with no useful information. The inner exception is null. The only thing I got is the stack trace. But I guess i am on to something. I added the framework source files to an empty project instead of the assembly and debugged it step by step. I guess it has something to do with unsafe code, because I stumpled across something like that that last night. I will look this up when I am back from work. \$\endgroup\$
    – Ello
    Apr 28, 2014 at 9:11
  • \$\begingroup\$ Do you really expect an inner exception from ArgumentNullException, the exception thrown early when an argument is incorrectly null? Do you know which argument was null where? The stack trace should take you straight to it. \$\endgroup\$
    – Magus
    Apr 28, 2014 at 14:28

1 Answer 1

0
\$\begingroup\$

I got it to work. I updated all Versions and build the Assembly from Source and invoked the DLLs. Now it works as expected.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .