2
votes

I need to communicate some constantly changing data to my pixel shader. I have a texture2d that I am passing to my pixel shader via a texture parameter. Before I call the shader I need to update the data in the texture.

        emittingPositions.SetData(emittingPositionsBuffer); //Set the data on the texture
        animationEffect.Parameters["emittersMap"].SetValue(emittingPositions); //Tell the shader about the texture data
        //go on to do the actual drawing calls to use the pixel shader

The problem is that when I do this I get an exception:

"You may not call SetData on a resource while it is actively set on the GraphicsDevice. Unset it from the device before calling SetData."

How do I "unset it from the device"? Or should I be taking a different approach here?

1
Which line is triggering the exception?Justin Self
The second line that calls .SetValueMr Bell

1 Answers

5
votes

The first texture is set in the GraphicsDevice.Textures array with the index 0.

so you have to do this:

 GraphicsDevice.Textures[0] = null;