Stack Overflow c#

Рейтинг: 0Ответов: 1Опубликовано: 21.11.2014

Срабатывает, работает, потом перестает (программа не отвечает). В дебаге пишет, что стэк переполнен. Где могла затаиться проблема?

public partial class Form1 : Form
{
    List<PictureBox> pb = new List<PictureBox>();

    //PictureBox[] pb = new PictureBox[5];
    Bitmap top = new Bitmap(@"C:\\Users\\MAKADORE#\\Desktop\\FlappyBirds\\truba_top.bmp");
    Bitmap bottom = new Bitmap(@"C:\\Users\\MAKADORE#\\Desktop\\FlappyBirds\\truba_bot.bmp");
    Random r = new Random();

    int PointStartTop = 1;
    int PointStartBottom = 850;

    public Form1()
    {
        DoubleBuffered = true;
        InitializeComponent();
        pullGame();

        MouseClick += startMouse;

    }

    public void UseDefaults()
    {
        //PointStartTop = 850;
        //PointStartBottom = 850;
    }

    public void startMouse(object sender, MouseEventArgs e)
    {
        while (true)
        {
            startGame();
        }
    }

    public void startGame()
    {
        for (int i = 0; i < 5; i++)
        {
            pb[i].Location = new Point(pb[i].Location.X - 1, 0);
            Thread.Sleep(2);
        }

        LocationChecker(pb);

        //if (num + 1 != pb.Count)
        //{
        //    return startGame(num + 1);
        //}
        //else
        //{
        //    return startGame(0);
        //}
    }

    public void LocationChecker(List<PictureBox> pb)
    {
        if (pb.First().Location.X <= -110)
        {
            pb.Remove(pb.First());
        }
    }

    public void pullGame()
    {
        for (int i = 0; i < 5; i++)
        {
            pb.Add(new PictureBox());
            pb[i].Location = new Point(PointStartTop, 0);
            pb[i].SizeMode = PictureBoxSizeMode.AutoSize;
            pb[i].Image = top;
            PointStartTop += 280;
        }

        for (int i = 0; i < 5; i++)
        {
            this.Controls.Add(pb[i]);
        }
    }
}

Ответы

▲ 1

while (true){...} - не смущает?