title: I got a stack overflow error in my int main()
body: <p>I am writing a snake game and I got a stack overflow in <code>int main()</code> I don't know how to fix it.
  and I don't really know how to make heap variables :P. The error reads Severity Code    Description Project File    Line    Suppression State
  Warning C6262   Function uses '17444' bytes of stack:  exceeds /analyze:stacksize '16384'.  Consider moving some data to heap.</p>
  
  <p>Here is my main:</p>
  
  <pre><code>int main()
  {
      vector&lt;point&gt; snek;
      mt19937 mt_rand(time(0));
      snek.push_back({ 10,10 });
      snek.push_back({ 10,9 });
      snek.push_back({ 10,8 });
      snek.push_back({ 10,7 });
      int highscore = 0, score;
      bool tutorial = false;
      bool p = false;
      char move = 'w';
      char sure = 'f';
      string board[21][21];
      int direction = 2;
      point apple;
      apple.x = (mt_rand() % 19) + 1;
      apple.y = (mt_rand() % 19) + 1;
      for (int i = 0; i &lt; 20; i++)
      {
          for (int j = 0; j &lt; 20; j++)
          {
              board[i][j] = "  ";
          }
      }
      bool loss = false;
      while (true)
      {
          score = snek.size() - 4;
          bool  appleEaten = false;
          if (snek[0].x == 0)
              loss = true;
          if (snek[0].x == 20)
              loss = true;
          if (snek[0].y == 0)
              loss = true;
          if (snek[0].y == 20)
              loss = true;
          if (loss)
          {
              system("CLS");
              if (score &gt; highscore)
              {
                  highscore = score;
              }
              cout &lt;&lt; "You lost with a score of " &lt;&lt; snek.size() - 4 &lt;&lt; endl;
              cout &lt;&lt; "Your highscore for this session is " &lt;&lt; highscore &lt;&lt; endl;
              cout &lt;&lt; "Press any key to play again" &lt;&lt; endl;
              cout &lt;&lt; "Press RMB to quit" &lt;&lt; endl;
              while (true)
              {
                  if (GetAsyncKeyState(VK_RBUTTON))
                  {
                      system("CLS");
                      cout &lt;&lt; "Are you sure you want to quit? Your highscore for this session will be reset" &lt;&lt; endl;
                      cout &lt;&lt; "Press Q to quit and P to play again" &lt;&lt; endl;
                      sure = _getch();
                      if (sure == 'q' || sure == 'Q')
                      {
                          _Exit(0);
                      }
                      if (sure == 'p' || sure == 'P')
                      {
                          p = true;
                      }
                  }
                  if (_kbhit() || p)
                  {
                      for (int i = 0; i &lt; 20; i++)
                      {
                          for (int j = 0; j &lt; 20; j++)
                          {
                              board[i][j] = "  ";
                          }
                      }
                      snek.clear();
                      snek.push_back({ 10,10 });
                      snek.push_back({ 10,9 });
                      snek.push_back({ 10,8 });
                      snek.push_back({ 10,7 });
                      loss = false;
                      p = false;
                      break;
                  }
              }
          }
          Sleep(10);
          if (_kbhit())
          {
              move = _getch();
          }
          switch (move)
          {
          case 'w':
              loss = goTo({ (snek[0].x - 1),snek[0].y }, snek);
              Sleep(10);
              break;
          case 'a':
              loss = goTo({ snek[0].x ,(snek[0].y - 1) }, snek);
              Sleep(10);
              break;
          case 's':
              loss = goTo({ (snek[0].x + 1),snek[0].y }, snek);
              Sleep(10);
              break;
          case'd':
              loss = goTo({ snek[0].x ,(snek[0].y + 1) }, snek);
              Sleep(10);
              break;
          }
          board[apple.x][apple.y] = " 0";
          for (int k = 0; k &lt; snek.size() - 1; k++)
          {
              board[snek[k].x][snek[k].y] = " *";
          }
          board[snek[snek.size() - 1].x][snek[snek.size() - 1].y] = "  ";
          if (apple.x == snek[0].x &amp;&amp; apple.y == snek[0].y)
          {
              snek.push_back({ snek[snek.size() - 1].x + 1,snek[snek.size() - 1].y });
              appleEaten = true;
          }
          if (appleEaten)
          {
              makeFood(apple, snek);
          }
          for (int i = 0; i &lt; 20; i++)
          {
              board[0][i] = "--";
              board[20][i] = "--";
          }
          for (int i = 0; i &lt; 20; i++)
          {
              board[i][0] = '|';
              board[i][20] = '|';
          }
          if (!tutorial)
          {
              cout &lt;&lt; "You are a snake." &lt;&lt; endl;
              cout &lt;&lt; "Your body looks like this" &lt;&lt; endl;
              cout &lt;&lt; "*****" &lt;&lt; endl;
              cout &lt;&lt; "Move with WASD" &lt;&lt; endl;
              cout &lt;&lt; "If you eat the apples, which look like this " &lt;&lt; endl &lt;&lt; "0" &lt;&lt; endl;
              cout &lt;&lt; "You get bigger. If you try to eat yourself or run into walls, you lose" &lt;&lt; endl;
              cout &lt;&lt; "Click RMB to begin";
              while (true)
              {
                  if (GetAsyncKeyState(VK_RBUTTON))
                  {
                      system("CLS");
                      tutorial = true;
                      break;
                  }
              }
          }
          system("CLS");
          for (int i = 0; i &lt; 21; i++)
          {
              for (int j = 0; j &lt; 21; j++)
              {
                  cout &lt;&lt; board[i][j];
              }
              cout &lt;&lt; endl;
          }
          cout &lt;&lt; "Score: " &lt;&lt; score;
      }
  }
  </code></pre>