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 8183041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:02:25+00:00 2026-06-07T01:02:25+00:00

My code seems to compile okay, but when I try to run it, it

  • 0

My code seems to compile okay, but when I try to run it, it hangs very badly.

I’ve been following along with Riemers XNA tutorial here.

I’m pretty familiar with C#, but an expert by no means. I’ve had no problems getting any of this to work up to this point, and there are no errors or exceptions being thrown… it just hangs up. I’ve read on his related forum, where users discussed having other problems, usually relating to typos or code errors, but there’s nothing like this in there… everyone seems to be able to run it fine.

Is there something I’ve done wrong perhaps? The nested for-loop at the bottom seems a bit heavy-handed to me. screenWidth and screenHeight are 500 and 500.

BTW: this is run from the LoadContent override method, so it should only run once as far as I know.

    private void GenerateTerrainContour()
    {
        terrainContour = new int[screenWidth];

        for (int x = 0; x < screenWidth; x++)
            terrainContour[x] = screenHeight / 2;
    }

    private void CreateForeground()
    {
        Color[] foregroundColors = new Color[screenWidth * screenHeight];

        for (int x = 0; x < screenWidth; x++)
        {
            for (int y = 0; y < screenHeight; y++)
            {
                if (y > terrainContour[x])
                    foregroundColors[x + y * screenWidth] = Color.Green;
                else
                    foregroundColors[x + y * screenWidth] = Color.Transparent;
                fgTexture = new Texture2D(device, screenWidth, screenHeight, false, SurfaceFormat.Color);
                fgTexture.SetData(foregroundColors);
            }
        }
    }
  • 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-06-07T01:02:26+00:00Added an answer on June 7, 2026 at 1:02 am

    Probably something to do with the fact that you’re creating 250,000 screen sized textures (holy moly)!

    Resource allocation is always heavy – especially when you’re dealing with media such as sounds and images.

    It seems like you only really need one texture here, try moving fgTexture = new Texture2D(device, screenWidth, screenHeight, false, SurfaceFormat.Color); outside of the loop. Then try moving fgTexture.SetData(foregroundColors); outside of the loop too.

    private void CreateForeground()
    {
        Color[] foregroundColors = new Color[screenWidth * screenHeight];
    
        fgTexture = new Texture2D(device, screenWidth, screenHeight, false, SurfaceFormat.Color);
    
        for (int x = 0; x < screenWidth; x++)
        {
            for (int y = 0; y < screenHeight; y++)
            {
                if (y > terrainContour[x])
                    foregroundColors[x + y * screenWidth] = Color.Green;
                else
                    foregroundColors[x + y * screenWidth] = Color.Transparent;
            }
        }
    
        fgTexture.SetData(foregroundColors);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I compile the following code with g++, the object of class A seems
Why won't the following C code compile? It seems like it should just change
My code seems to run but it does not display the result any result
The following javascript code seems to leak memory but I’m not sure why. I’ve
The following code seems to be impossible to compile no matter how hard I
Is my code correct? It seems can compile but does not work properly.. CString
The following code seems to be just too much, for getting a single count
From what I have read java (usually) seems to compile java to not very
When I compile the following code using g++ class A {}; void foo(A&) {}
I can't seem to get the following trivial code to compile/link and the problem

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.