Jump to content
  • Advertisement
Sign in to follow this  
adt7

XNA: Texture2D.SetData Exception

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I posted a topic regarding this a while ago, but it got filled up with other stuff and I've done some work on this since, so apologies for the repeat. I'm currently trying to implement geometry clipmaps in XNA using vertex texture fetch. I'm performing toroidial updates of my heightmap texture on the CPU each frame it's required (IE. only those where the camera moves). I'm currently doing this by using the GetData method to read out my texture into an array of Vector4s, performing my updates, then using SetData to put it back into the texture.
Vector4[] textureArray = new Vector4[texture.Width * texture.Height];
texture.GetData(textureArray);

// Manipulate Texture Data

texture.SetData(textureArray);
However as soon as I move my camera (forcing an update), I get the following exception thrown.
"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."
In my last topic MJP helpfully pointed out that this means one of two things, either: - I'm in the middle of a predicated tiling bracket - The device is still using the Texture I'm certain I'm not in the middle of a tiling bracket, as my texture is SurfaceFormat Vector4, and is only 256x256 right now, which is far too small to trigger one. So obviously my problem is that the device is still using the texture. Using "device.Texture[0] = null" before the SetData call does not work. My current "solution" is to recreate the texture object each time. Which is clearly not the right way to do things, and strains the CPU when you move over the terrain at high speed.
Vector4[] textureArray = new Vector4[texture.Width * texture.Height];
texture.GetData(textureArray);

// Manipulate Texture Data

texture = new Texture2D(device, ... );
texture.SetData(textureArray);
My problem stems from the CPU and GPU not being in sync with each other, is there anyway to force them to be? (All of this code is within my Draw call). I know I could solve this by setting up a double or triple buffering solution, but I'm sure there must be an easier way. In DirectX it works just fine by using a locked rectangle, so why not in XNA? (I believe Get/SetData are the same basic concept?) Another solution would be to move the texture manipulation over to the GPU, but unfortunately I have neither the time nor the skill to do that right now. Any help on this would be greatly appreciated. [Edited by - adt7 on May 21, 2009 7:29:52 AM]

Share this post


Link to post
Share on other sites
Advertisement
Surely there must be a way to allow for runtime modification of textures within XNA without resorting to double/triple buffering? Especially considering that doesn't really fit my needs.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!