[SOLVED] BasicEffect error with vertices passed

Me again.
Basically, the error is exactly what’s passed. When I call pass.Apply(), I get an error saying the vertices supplied don’t match the required input.
The creation of the effect:

            SkyPlaneEffect = new BasicEffect(Game.GraphicsDevice)
            {
                VertexColorEnabled = false,
                FogEnabled = true,
                FogStart = 0,
                FogEnd = 64 * 0.8f,
                LightingEnabled = true,
            };

The vertices added:

            var plane = new[]
            {
                new VertexPositionColor(new Vector3(-64, 0, -64), Color.White),
                new VertexPositionColor(new Vector3(64, 0, -64), Color.White),
                new VertexPositionColor(new Vector3(-64, 0, 64), Color.White),

                new VertexPositionColor(new Vector3(64, 0, -64), Color.White),
                new VertexPositionColor(new Vector3(64, 0, 64), Color.White),
                new VertexPositionColor(new Vector3(-64, 0, 64), Color.White)
            };
            SkyPlane = new VertexBuffer(Game.GraphicsDevice, VertexPositionColor.VertexDeclaration,
                plane.Length, BufferUsage.WriteOnly);

Then finally the draw call.

            Game.GraphicsDevice.Clear(AtmosphereColor);
            Game.GraphicsDevice.SetVertexBuffer(SkyPlane);
            var position = Player.Camera.Position;
            var yaw = Player.Player.Yaw;
            Player.Camera.Position = Vector3.Zero;
            Player.Player.Yaw = 0;
            Player.Camera.Update(gameTime);
            Player.Camera.ApplyTo(SkyPlaneEffect);
            Player.Player.Yaw = yaw;
            Player.Camera.ApplyTo(CelestialPlaneEffect);
            Player.Player.Position = position;
            // Sky
            SkyPlaneEffect.FogColor = AtmosphereColor.ToVector3();
            SkyPlaneEffect.World = Matrix.CreateRotationX(MathHelper.Pi)
                * Matrix.CreateTranslation(0, 100, 0)
                * Matrix.CreateRotationX(MathHelper.TwoPi * CelestialAngle);
            SkyPlaneEffect.AmbientLightColor = WorldSkyColor.ToVector3();
            foreach (var pass in SkyPlaneEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                SkyPlaneEffect.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            }

All values are initialized (none that are null) but the error throws right at pass.Apply(). Sadly, Visual Studio is kind of bad with tracking exactly where the error occurs at with .Draw calls with MonoGame so I’m unsure of if it’s actually pass.Apply() that’s throwing the error.

You have VertexColorEnabled set to false but your vertices do have color, so it doesn’t match up.
I also think enabling lighting requires normals. EDIT: Yeah, just checked and it does.

1 Like

Ah that it does. I thought I had them switched but I guess not. Thanks for that catch.

1 Like