why does my game wont debug

I’m using visual studio community 2022 or it might be something from my code:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace flappy_bird
{
    public class Game1 : Game
    {
        private GraphicsDeviceManager _graphics;
        private SpriteBatch _spriteBatch;
        private Texture2D player;
        private Vector2 pMov;
        private int height;
        private int width;

        public Game1()
        {
            _graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            _graphics.PreferredBackBufferHeight = 480;
            _graphics.PreferredBackBufferWidth = 480;
            _graphics.ApplyChanges();

            height = _graphics.PreferredBackBufferHeight;
            width = _graphics.PreferredBackBufferWidth;

            base.Initialize();
        }

        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            Content.Load<Texture2D>("player");
            pMov = new Vector2(height/2, width/2);
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            // TODO: Add your update logic here
            for (int yv = 1; yv > 0; yv++)
            {
                pMov.Y -= yv;
            }

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            _spriteBatch.Begin();
            _spriteBatch.Draw(player, pMov, Color.White);
            _spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}

whenever i try to debug my game the window will just not respond eternally.

This loop will never exit.

you have an endless loop in your update function, as pointed out above.

In VS you can just “pause” into debugger at any point in time and you can see where the code is currently executed - normally it should be easy to find any accidental infinite loops that way. So whenever you find anything unresponsible - pause the debugger and check why it’s looping.

4 Likes

yes , menu The Debug ->BreakAll is how you find these in the vs, or the debug pause button. Also its how you find when you have a deadlocked thread or something… And when you suddenly have a major performance bottleneck, or lag, before profiling, do a BreakAll and its most likley going to stop in the very method that scales poorly or itsnt exiting or in a bad state, the culprite that needs a careful analysis.