System.InvalidOperationException: You may not modify a resource that has been set on a device, or after it has been used within a tiling bracket.

May 23, 2009 at 2:22 PM

Hi,

When I tried to draw hardware instanced BatchModel I got this:

System.InvalidOperationException

Additional information: The operation was aborted. You may not modify a resource that has been set on a device, or after it has been used within a tiling bracket.

at Vertices.cs, line 194

 

Stack Trace:

> Xen.dll!Xen.Graphics.Vertices<Xen.Graphics.StreamFrequency.InstanceMatrix>.Implementation.WriteBlock(Xen.DrawState state = {Xen.DrawState}, Xen.Graphics.StreamFrequency.InstanceMatrix[] data = {Xen.Graphics.StreamFrequency.InstanceMatrix[256]}, int startIndex = 4, int start = 256, int length = 4, object target = {Microsoft.Xna.Framework.Graphics.DynamicVertexBuffer}, object parent = {Xen.Graphics.Vertices<Xen.Graphics.StreamFrequency.InstanceMatrix>}) Line 194 + 0x19 bytes C#
  Xen.dll!Xen.Graphics.Bufffer<Xen.Graphics.StreamFrequency.InstanceMatrix>.WriteBuffer(Xen.DrawState state = {Xen.DrawState}, int startIndex = 4, int bytesToWrite = 256, object target = {Microsoft.Xna.Framework.Graphics.DynamicVertexBuffer}, object parent = {Xen.Graphics.Vertices<Xen.Graphics.StreamFrequency.InstanceMatrix>}) Line 258 + 0x1d bytes C#
  Xen.dll!Xen.Graphics.Bufffer<Xen.Graphics.StreamFrequency.InstanceMatrix>.UpdateDirtyRegions(Xen.DrawState state = {Xen.DrawState}, object target = {Microsoft.Xna.Framework.Graphics.DynamicVertexBuffer}, object parent = {Xen.Graphics.Vertices<Xen.Graphics.StreamFrequency.InstanceMatrix>}) Line 89 + 0x16 bytes C#
  Xen.dll!Xen.Graphics.Vertices<Xen.Graphics.StreamFrequency.InstanceMatrix>.Xen.Graphics.IDeviceVertexBuffer.GetVertexBuffer(Xen.DrawState state = {Xen.DrawState}) Line 497 + 0x13 bytes C#
  Xen.dll!Xen.Graphics.VerticesGroup.Draw(Xen.DrawState state = {Xen.DrawState}, Xen.Graphics.IIndices indices = {Xen.Graphics.Indices<ushort>}, Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType = TriangleList, Xen.Graphics.StreamFrequency frequency = {Xen.Graphics.StreamFrequency}, int primitveCount = 2147483647, int startIndex = 0, int vertexOffset = 0) Line 636 + 0x6 bytes C#
  Xen.dll!Xen.Graphics.VerticesGroup.Draw(Xen.DrawState state = {Xen.DrawState}, Xen.Graphics.IIndices indices = {Xen.Graphics.Indices<ushort>}, Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType = TriangleList, Xen.Graphics.StreamFrequency frequency = {Xen.Graphics.StreamFrequency}) Line 576 + 0x12 bytes C#
  Xen.dll!Xen.DrawState.DrawBatch(Xen.Graphics.VerticesGroup vertices = {Xen.Graphics.VerticesGroup}, Xen.Graphics.IIndices indices = {Xen.Graphics.Indices<ushort>}, Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType = TriangleList, int count = 4) Line 342 + 0xf bytes C#
  Xen.dll!Xen.DrawState.DrawBatch(Xen.Graphics.IVertices vertices = {Xen.Graphics.Vertices<byte>}, Xen.Graphics.IIndices indices = {Xen.Graphics.Indices<ushort>}, Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType = TriangleList, Xen.Callback<bool,int,Xen.ICuller> CanDrawItem = null, Microsoft.Xna.Framework.Matrix[] instances = {Microsoft.Xna.Framework.Matrix[8]}, int instancesLength = 4, int startIndex = 0) Line 193 + 0x9 bytes C#
  Xen.dll!Xen.DrawState.DrawBatch(Xen.Graphics.IVertices vertices = {Xen.Graphics.Vertices<byte>}, Xen.Graphics.IIndices indices = {Xen.Graphics.Indices<ushort>}, Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType = TriangleList, Xen.Callback<bool,int,Xen.ICuller> CanDrawItem = null, Microsoft.Xna.Framework.Matrix[] instances = {Microsoft.Xna.Framework.Matrix[8]}, int instancesLength = 4) Line 124 C#
  Xen.Ex.dll!Xen.Ex.Graphics.BatchModel.Draw(Xen.DrawState state = {Xen.DrawState}) Line 241 + 0x1f bytes C#
  Xen.Ex.SeventhGear.dll!Xen.Ex.SeventhGear.StaticBatchGeometry.Draw(Xen.DrawState state = {Xen.DrawState}) Line 158 + 0xc bytes C#
  Xen.Ex.SeventhGear.dll!Xen.Ex.SeventhGear.Scene.Draw(Xen.DrawState state = {Xen.DrawState}) Line 60 + 0x7 bytes C#
  Xen.dll!Xen.Graphics.DrawTarget.Draw(Xen.DrawState state = {Xen.DrawState}) Line 343 + 0x8 bytes C#
  GopherGame.exe!GopherGame.GameMain.Draw(Xen.DrawState state = {Xen.DrawState}) Line 296 + 0xc bytes C#
  Xen.dll!Xen.Application.OnDraw(Xen.DrawState state = {Xen.DrawState}) Line 935 + 0x7 bytes C#
  Xen.dll!Xen.XNALogic.Draw() Line 221 + 0xc bytes C#
  Xen.dll!Xen.XNAGameAppWrapper.Draw(Microsoft.Xna.Framework.GameTime gameTime = {Microsoft.Xna.Framework.GameTime}) Line 401 + 0xb bytes C#
  Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.DrawFrame() + 0x9a bytes  
  Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.Tick() + 0x2fc bytes  
  Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.HostIdle(object sender = {Microsoft.Xna.Framework.XboxGameHost}, System.EventArgs e = {System.EventArgs}) + 0x6 bytes  
  Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.GameHost.OnIdle() + 0x19 bytes  
  Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.XboxGameHost.Run() + 0x21 bytes  
  Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.Run() + 0xbf bytes  
  Xen.dll!Xen.XNAGameAppWrapper.Xen.IXNAAppWrapper.Run() + 0x6 bytes  
  Xen.dll!Xen.XNALogic.Run() Line 134 + 0xb bytes C#
  Xen.dll!Xen.Application.Run() Line 847 + 0xb bytes C#
  GopherGame.exe!GopherGame.Program.Main(string[] args = {string[0]}) Line 14 + 0x6 bytes C#

May 23, 2009 at 2:56 PM

Addition: this happens when I try to render same BatchModel several times in a row with a different shaders, like this:

 

if (state.SupportsHardwareInstancing)
  {
  for (int i = 0; i < _instances.Count; i++)
  _instances[i].Draw(state);

  _batchmodel.SetShaderOverride(shadow);
  _batchmodel.Draw(state);

  for (int i = 0; i < _instances.Count; i++)
  _instances[i].Draw(state);

  _batchmodel.SetShaderOverride(cel);
  _batchmodel.Draw(state);

  for (int i = 0; i < _instances.Count; i++)
  if (!_instances[i].Shadow)
  _instances[i].Draw(state);

  _batchmodel.SetShaderOverride(outline);
  _batchmodel.Draw(state);
  }

 

Each _instances[i] is similar to your instance class from the BatchModel tutorial.

 

I tried to make 3 models, i.e. _batchmodel1, _batchmodel2, etc. with the same geometry - and three corresponding instance class lists. Didn't help.

Coordinator
May 24, 2009 at 1:11 AM

OK I know why this will be happening and I can reproduce it.

In the mean time, as a temporary measure you will be able to stop it occurring if you can prevent predicated tiling enabling on the xbox.
This means either turning off antialiasing or lowering the resolution enough so that the render target/depth fit into the 10mb EDRAM in one go (1280x720 without AA fits when using a 32bpp colour format)

This is occurring  because the instance data needs to be copied into dynamic vertex buffers at runtime. However I'm trying to be clever and storing these buffers - so when this error occurs, it's using a buffer twice within the same frame (writing some data to the front, some to the back - which is perfectly valid thing to do, but XNA detects it and thinks it's overwriting the entire buffer twice during the frame (which it isn't) and throws this exception to say you can't do that.

So the question is if I just prevent this from happening outright on the xbox (reusing a buffer twice during a frame - which means potentially more memory) or try and detect if tiling is active as well...

May 24, 2009 at 7:58 AM

I know it's a pretty annoying XNA issue. I'm using 1280x720 rendertarget with depth and stencil, with multisampling. Can't change that to lower, really.

Can we arrange some workaround so user can choose both ways? I mean reuse the buffer (like it does now) or use another for the same data.

 

Coordinator
May 24, 2009 at 8:00 AM

What I meant was I'll fix the bug in the next update, but in the meantime you can disable msaa so the error doesn't occur.
:-)

Oct 6, 2010 at 5:22 PM

Hi.

Recently I've also run into this problem (or at least I think I did).
Before I start, note that all my tests/applications here stated were tested on the Xbox 360.

I've been trying for a while to do an image/video gallery. To do so I load the images/videos and draw them in the screen. Once I don't need them, I use dispose in order to free some resources. But once I dispose the resources, problems appear.

After some days searching for the source of the problem (in the code and in the forums) I tried to start from zero. I used the "VideoPlayback_Sample_31" from XNA and built a simple video gallery where the user jumps between two videos with a click. So far so good.

The application starts with VideoFile1 and when the user changes to VideoFile2, the VideoFile1.Dispose() is called and the VideoFile2 related content is loaded and played. Smooth... ALMOST without any problems.

During my tests with the (XNA only) application, I noted that when I jumped between videos too fast (more than 4 times per second) the application would crash without any exception or any other signal.

Ok, at this time I've realized that I could not ask too much for GPU resources to get disposed/created at fast rates.

I moved on to test the same application but using XEN Graphics API. I've build an application with exact the same behaviour and put it to test. This time I got stuck in the first time I jumped between videos with a "System.InvalidOperationException" stating "Additional information: The operation was aborted. You may not modify a resource that has been set on a device, or after it has been used within a tiling bracket." (At this point I found this thread!).

After reading it, I tried to decrease the resolution, disabled the MSAA and the application still throws the same exception. By the way, the two videos used have the same resolution: 720:576px.

Have anyone found any workarround/solution to this problem?