My game allows the user to zoom out indefinitely (it's a gravity simulation, with text displayed below each planet), and when doing so the game takes longer and longer to start rendering each time the user zooms out, until it eventually crashes with a std::bad_alloc exception. Once the view actually zooms out, the lag stops until you try to zoom out again.
Offending code:
sf::Text text;
text.setFont(font);
text.setCharacterSize(char_size * camera.GetZoom());
text.setFillColor(sf::Color::White);
if (temp_display)
{
for (int i = 0, w = planets.size(); i < w; i++)
{
text.setString(to_string(planets.at(i).GetTemperature()));
text.setPosition(planets.at(i).GetPosition() + sf::Vector2f(text.getLocalBounds().width * -0.5f, planets.at(i).GetRadius() + char_size * camera.GetZoom()));
window.draw(text);
text.setString(to_string(planets.at(i).population));
text.setPosition(
text.getPosition() + sf::Vector2f(0, camera.GetZoom() * 5 + text.getLocalBounds().height));
window.draw(text);
text.setString(to_string(planets.at(i).tech_level));
text.setPosition(
text.getPosition() + sf::Vector2f(0, camera.GetZoom() * 5 + text.getLocalBounds().height));
window.draw(text);
}
The camera just holds a view, a float (zoom), and methods to change the zoom, move the camera, and return the zoom.
If text is not being rendered, it works perfectly with no lag when zooming. There's also no lag when zooming in, zooming back out after zooming in does not lag, even if it lagged to zoom out to that size the first time.