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

Author Topic: Creating a Vector of Shapes  (Read 4510 times)

0 Members and 2 Guests are viewing this topic.

RadWayne

  • Newbie
  • *
  • Posts: 2
    • View Profile
Creating a Vector of Shapes
« on: January 10, 2014, 11:04:06 pm »
I have no problem creating and using shapes stored in a vector but when I try and close the window while using a shape stored in a vector I "trigger a breakpoint".
The error is being thrown from free.c from a  function used to free a memory block in the heap.

What exactly is happening and why is there a problem freeing memory?

int main()
{
   
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
        sf::RectangleShape rect1(sf::Vector2f(100,50));
        rect1.setFillColor(sf::Color(255,0,0));
        std::vector <sf::RectangleShape> vectorRect(1);
        vectorRect[0]=rect1;

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

                window.draw(vectorRect[0]);
        window.display();
    }

    return 0;
}

Assassin0795

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Creating a Vector of Shapes
« Reply #1 on: January 12, 2014, 03:08:34 am »
Instead of just:

window.draw(vectorRect[0]);
window.display();

Try:

window.clear();
window.draw(vectorRect[0]);
window.display();

I had funky issues with my program because I forgot to add window.clear() once.

RadWayne

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Creating a Vector of Shapes
« Reply #2 on: January 12, 2014, 03:14:54 am »
Nope.

It has something to do with SFML trying to free memory allocated for the vector. Someone else suggested I compile SFML on my own so I'm going to try that.

Omega

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Creating a Vector of Shapes
« Reply #3 on: January 12, 2014, 05:25:53 am »
It works fine for SFML 2.0. Are you using a different version?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Creating a Vector of Shapes
« Reply #4 on: January 12, 2014, 02:40:28 pm »
From a logic point of view, you shouldn't be rendering anything when the window is closed. I think it's a good idea to avoid this situation, even if there were no technical problems with it.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything