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

Author Topic: Crash when using high character size on text  (Read 1355 times)

0 Members and 1 Guest are viewing this topic.

Idrialite

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Crash when using high character size on text
« on: September 21, 2017, 03:57:01 pm »
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:

(click to show/hide)

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.
« Last Edit: September 21, 2017, 03:59:26 pm by Idrialite »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Crash when using high character size on text
« Reply #1 on: September 21, 2017, 04:44:12 pm »
You should stop increasing the character size after a given limit, and scale the text instead. Increasing the character size involves creating and filling more and more textures on GPU side, until you reach one or the other hardware/code limit (no more VRAM, can't render even a single glyph to a texture, etc.).
Laurent Gomila - SFML developer

Idrialite

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Crash when using high character size on text
« Reply #2 on: September 21, 2017, 04:56:05 pm »
Yeah, that worked, thanks.

 

anything