Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:59:43+00:00 2026-05-27T15:59:43+00:00

I trying to use the SetData method as a part of a pixel based

  • 0

I trying to use the SetData method as a part of a pixel based Collision Detection mechanism I use in my game.
In general, I want to set a texture’s overlapping pixels to transparent.

While trying to use the SetData I keep receiving the following 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.”

I did manage to find some almost similar questions dealing with this exception in StockOverFlow, yet I am still not sure how to deal with this Exception:

  1. I’ve tried to call SetData from the Draw method, yet the Exception keeps appearing.
  2. I’ve tried to understand whether I should somehow remove the texture from the GraphicsDevice, but the only way to do this seems to be using the texture’s index in GraphicsDevice.Textures[idx] and set it to null. What if I don’t hold this index in my class?

My game, naturally I think, holds multiple textures inside it (Some of them are added to Game.Components as well). Perhaps this might be the root of the problem?

I am attaching a very small part of my code… I don’t see a real reason to post more than that.

private void collisionDetected()
{...
        for (int col = collisionLeftCordinate; col < collisionRightCordinate; col++)
        {
            for (int row = collisionTopCordinate; row < collisionBottomCordinate - 1; row++)
            {
                if (m_BarrierPixels[col + row * (int)this.Texture.Width] != Color.Transparent)
                {
                    m_BarrierPixels[col + row * (int)this.Texture.Width] = Color.Transparent;
                    m_TransparentPixelsCounter++;
                }
            }
        }

        this.Texture.SetData(m_BarrierPixels);
...}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:59:44+00:00Added an answer on May 27, 2026 at 3:59 pm
    1. collision detection over Pixel’s are not efficient, you have to cold color arrays, where you have to care about scale and rotation factors.

    2. if you are working on renderTarget’s you should set renderTarget to null, so that you can change the pixel, if you are not using renderTarget, you should change the pixel in Update (which is better) if you want to do it in Draw method, then you should call is before spriteBatch.Begin .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the SetXData method on the AutoCAD 2007 COM object,
I was trying use a set of filter functions to run the appropriate routine,
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying use a Java Uploader in a ROR app (for its ease
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use a guid as a resource id in a rest url but
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.