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

  • Home
  • SEARCH
  • 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 6786987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:18:40+00:00 2026-05-26T17:18:40+00:00

There is a problem out of memory exception when exucuting this code. The code

  • 0

There is a problem “out of memory exception” when exucuting this code. The code takes rapid photos of the main board and stores it to be recompiled into a movie later.

If there is another way to make a replay of the field it would be much appreciated as now I have to take pictures of the board then recompile it into a avi movie.
Any help please.

 public class JSTART_Main : Microsoft.Xna.Framework.Game
{
    private GraphicsDeviceManager graphics;
    private SpriteBatch spriteBatch;
    private Texture2D background;
    private Rectangle mainFrame;
    private SpriteFont font;

    private bool finished = false;
    private BackgroundWorker bw = new BackgroundWorker();
    private Navigation navigation;

    public JSTART_Main()
    {
        graphics = new GraphicsDeviceManager(this);
        this.graphics.PreferredBackBufferWidth = 1280;
        this.graphics.PreferredBackBufferHeight = 768;
        navigation = new Navigation();
        navigation.graphics = graphics;
        navigation.window = Window;
        navigation.CreateClasses();

        //this.graphics.IsFullScreen = true;
        Content.RootDirectory = "Content";
        this.IsMouseVisible = true;

        navigation.controls.CreateControls();
        bw.WorkerSupportsCancellation = true;

        bw.DoWork += new DoWorkEventHandler(bw_screenshots);

    }

    protected override void Initialize()
    {
        base.Initialize();
        bw.RunWorkerAsync();         
    }
    void bw_screenshots(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;


            capture();
            capture();

            if ((worker.CancellationPending == true))
            {
                e.Cancel = true;

            }
            else
            {
                bw.Dispose();

            }              
        }
    void capture()
    {

        while (finished == false)
        {              
                count += 1;
                string counter = count.ToString();

                int w = GraphicsDevice.PresentationParameters.BackBufferWidth;
                int h = GraphicsDevice.PresentationParameters.BackBufferHeight;

                //force a frame to be drawn (otherwise back buffer is empty) 
                Draw(new GameTime());

                //pull the picture from the buffer 
                int[] backBuffer = new int[w * h];
                GraphicsDevice.GetBackBufferData(backBuffer);

                //copy into a texture 
                Texture2D texture = new Texture2D(GraphicsDevice, w, h, false, GraphicsDevice.PresentationParameters.BackBufferFormat);
                texture.SetData(backBuffer);                
                    //save to disk 
                    Stream stream = File.OpenWrite(counter + ".jpg");

                    texture.SaveAsJpeg(stream, w, h);
                    stream.Flush();
                    stream.Close();
                    texture.Dispose();

             }

    }
    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        background = Content.Load<Texture2D>("Background");
        mainFrame = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
        font = Content.Load<SpriteFont>("font");

    }

    protected override void UnloadContent()
    {

    }
    int count = 0;

    protected override void Update(GameTime gameTime)
    {

        //if (Keyboard.GetState().IsKeyDown(Keys.Escape))
        //this.Exit();
        foreach (Unit enemy in navigation.players.enemies.Values)
        {
            enemy.EnemyAI(navigation.aiCollision);
        }
        navigation.input.UpdateKeyboard();
        navigation.networking.Receive();
        navigation.players.SpotEnemy();
        navigation.input.UpdateMouse();

        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        try
        {
            base.Draw(gameTime);

            spriteBatch.Begin();
            spriteBatch.Draw(background, mainFrame, Color.White);
            spriteBatch.DrawString(font, "X: " + navigation.players.server.pos.X.ToString() + "\nY: " + navigation.players.server.pos.Y.ToString(), new Vector2(22, 22), Color.White);
            spriteBatch.End();
            navigation.players.server.LoadContent(Content);
            navigation.players.server.Draw(spriteBatch, Color.Transparent);
            foreach (MainObject map in navigation.players.map)
            {
                map.LoadContent(Content);
                map.Draw(spriteBatch);
            }

            foreach (Unit enemy in navigation.players.enemies.Values)
            {
                if (navigation.controls.cbxShowEnemies.Checked || enemy.visible == true)
                {
                    enemy.LoadContent(Content);
                    enemy.Draw(spriteBatch, Color.Red);
                }
            }

            foreach (Unit unit in navigation.players.players.Values)
            {
                if (unit != null && unit.visible)
                {
                    unit.LoadContent(Content);
                    unit.Draw(spriteBatch, Color.White);
                }
            }

        }
        catch (Exception )
        { }

    }
}

}

  • 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-26T17:18:41+00:00Added an answer on May 26, 2026 at 5:18 pm

    If you where able to draw the game and board once, surely you could do it another time. All you have to do is store the moves made by each unit, and just replay that.

    If you are trying to save it to an avi file consider writing each frame to the harddisk instead of saving them in memory.

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

Sidebar

Related Questions

A recent problem* left me wondering whether there is a text editor out there
Is there a problem with this type of implementation to wait for a batch
Is there significant problem, if I write the code for embedded linux system using
I'm debugging an out-of-memory exception. When I get the exception, the virtual bytes performance
Problem: There are a bunch of .lnk files on the C drive that point
Problem There are data gaps that need to be filled. Would like to avoid
Problem: There are a lot of different databases, which is populated by many different
Is there a problem with using IEnumerable<T> as a return type? FxCop complains about
is there any problem to install different oracle 11g versions. I mean if I
Is there a problem to using javascript for styling content? My website requires javascript.

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.