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

Author Topic: Using a for loop with RectangleShapes  (Read 1573 times)

0 Members and 1 Guest are viewing this topic.

mayday556

  • Newbie
  • *
  • Posts: 8
    • View Profile
Using a for loop with RectangleShapes
« on: December 05, 2013, 12:59:53 am »
I've been working on a secret project lately, and I needed a couple Rectangle Shapes for hidden reasons. I thought I could just use an array of Rectangle Shapes, because I needed to manipulate all of them using the same code, but when initializing their size, color, data, etc. I get an error saying:

A buffer overrun has occurred in SFML.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

The code I am using to initialize them is as follows:

const short bodyCount = 4;

sf::RectangleShape wolfBody[bodyCount];
for (int i = 0; i < bodyCount; i++)
{
        wolfBody[i].setSize(sf::Vector2f(32, 32));
        wolfBody[i].setFillColor(sf::Color::Red);
        wolfBody[i].setOrigin(16, 16);
}

Does anyone know what is wrong with this?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Using a for loop with RectangleShapes
« Reply #1 on: December 05, 2013, 03:02:58 am »
Well how exactly do you expect to initialize the shape if you never call the constructor...

Oh, and maybe avoid using raw fixed arrays, instead use something like std::vector<T>.
« Last Edit: December 05, 2013, 02:14:57 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Using a for loop with RectangleShapes
« Reply #2 on: December 05, 2013, 05:54:55 am »
Well how exactly do you expect to initialize the shape if you never call the constructor...
http://www.parashift.com/c++-faq/arrays-call-default-ctor.html

The code snippet isn't by itself the cause of the problem. You need to provide more code and generally more information.

http://en.sfml-dev.org/forums/index.php?topic=5559.msg36367#msg36367
http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything