You must have a spritebatch.begin call under renderer.drawall. Find where it is thats causing the error
Edit: sorry just realised you noted where the error is
Try remove your lighting effect and see if it still does it. It is probably your effect.
Spritebatch.end is the moment when all the spritebatches are actually drawn.
Perhaps your effect needs some parameters passed to it?
If I remove the effect and just do SpriteBatch.Begin with no arguments then it works. I think the error might be in LoadLights, if it has to do with parameters. Do you see anything wrong with this code?
public void LoadLights()
{
List<Vector3> lightData = new List<Vector3>();
foreach(Light light in world.loadedChunk.lights)
{
Vector2 screenCoords = ToScreenSpace(light.position);
lightData.Add(new Vector3(screenCoords.X, screenCoords.Y, light.intensity));
}
lighting.Parameters["lights"].SetValue(lightData.ToArray());
}
I have lights set as an array with 1000 ‘slots’ in the effect incase more lights are needed, but only load one, might that be the issue? I also set abreakpoint and verified that world.loadedChunk.lights does contain the light so it shouldn’t be trying to load nothing.
Update: Here’s the stack trace, if that helps
" at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)\r\n at Microsoft.Xna.Framework.Graphics.ConstantBuffer.SetParameter(Int32 offset, EffectParameter param)\r\n at Microsoft.Xna.Framework.Graphics.ConstantBuffer.SetParameter(Int32 offset, EffectParameter param)\r\n at Microsoft.Xna.Framework.Graphics.ConstantBuffer.Update(EffectParameterCollection parameters)\r\n at Microsoft.Xna.Framework.Graphics.EffectPass.Apply()\r\n at Microsoft.Xna.Framework.Graphics.SpriteBatcher.FlushVertexArray(Int32 start, Int32 end, Effect effect, Texture texture)\r\n at Microsoft.Xna.Framework.Graphics.SpriteBatcher.DrawBatch(SpriteSortMode sortMode, Effect effect)\r\n at PlatformGame.Render.Renderer.DrawAll() in C:\Code\CSharp\PlatformGame\Render\Renderer.cs:line 85\r\n at PlatformGame.App.Draw(GameTime gameTime) in C:\Code\CSharp\PlatformGame\App.cs:line 98\r\n at Microsoft.Xna.Framework.Game.DoDraw(GameTime gameTime)\r\n at Microsoft.Xna.Framework.Game.Tick()\r\n at Microsoft.Xna.Framework.SdlGamePlatform.RunLoop()\r\n at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)\r\n at PlatformGame.Program.Main() in C:\Code\CSharp\PlatformGame\Program.cs:line 11"
Not sure what to make of it really, but I’m still stuck on this.
I got it to work. I’m not exactly sure how, but my theory is that because I was only using the first element of the lights array, the shader got mad at me for loading useless data and broke. Adding a loop to iterate over the lights made it work, even though most of them are blank.
Yeah it doesn’t seem very efficient at all but it doesn’t let me use variable sized arrays so I don’t really see another option. At least not a simple one.