Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: unhandled exception stack overflow in sprite  (Read 2285 times)

0 Members and 1 Guest are viewing this topic.

AzkaIsHere

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
unhandled exception stack overflow in sprite
« on: April 07, 2018, 02:03:50 pm »
yesterday I wrote this code to make trees spawn randomly anywere in the map:

for (int i = 0; i < 1000; i++)
        {
                tree[i].setTexture(tr);
                tree[i].setPosition(rand() % 10560 + 0, rand() % 10560 + 0);
                tree[i].setScale(1, 2);
        }

and then

for (int i = 0; i < 1000; i++)
                {
                        app.draw(tree[i]);
                }

-------------------------------------

But today i wrote that again for yellow flowers:


        for (int i = 0; i < 1000; i++)
        {
                yellow_flower[i].setTexture(y_f);
                yellow_flower[i].setPosition(rand() % 10560 + 0, rand() % 10560 + 0);
        }

and then

                for (int i = 0; i < 1000; i++)
                {
                        app.draw(yellow_flower[i]);
                }


but when I added these new loops, this error occurs to me:

Unhandled exception at 0x01017D59 in MyGame.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00402000).
      
« Last Edit: April 07, 2018, 05:15:39 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: unhandled exception stack overflow in sprite
« Reply #1 on: April 07, 2018, 05:18:45 pm »
Do you declare your flowers and trees directly in main() like this?

sf::Sprite tree[1000];
sf::Sprite yellow_flower[1000];
Laurent Gomila - SFML developer

AzkaIsHere

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: unhandled exception stack overflow in sprite
« Reply #2 on: April 08, 2018, 04:35:45 pm »
thank you very much fixed it

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: unhandled exception stack overflow in sprite
« Reply #3 on: April 08, 2018, 05:45:21 pm »
That would be helpful if you could explicitly tell us what was wrong and how you fixed it ;)
Laurent Gomila - SFML developer

AzkaIsHere

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: unhandled exception stack overflow in sprite
« Reply #4 on: April 08, 2018, 07:26:22 pm »
I don't know for sure, I added the yellow flower and tree array with 1000 elements and it made this error, then I deleted the declarations and the error stopped... I think it was a glitch in the debug

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: unhandled exception stack overflow in sprite
« Reply #5 on: April 08, 2018, 09:25:13 pm »
If they were declared on the stack, and since the stack has a very limited size, then it's perfectly normal that you overflowed it with such big arrays.
Laurent Gomila - SFML developer