blueUserRed / forty-five

.Forty-Five is a deckbuilding card game set in the wild west. Collect and master powerful cards, battle different enemies and try not to end up six feet deep!
https://www.forty-five.at
GNU General Public License v3.0
21 stars 4 forks source link

Interacting with Backpack causes a Memory leak and causes Framerate to tank dramatically #112

Closed blueUserRed closed 6 months ago

blueUserRed commented 6 months ago

Description

When interacting with the Backpack (e.g. swapping cards in the deck) a lot, the framerate goes down dramatically. This happens because these changes cause functions like Backpack::reloadDeck to be called, which in turn calls Backpack::getCard for every card in the deck, generating a new texture each time. Also the old textures are not disposed, causing a significant memory leak. Sorting cards or moving cards from the deck to the backpack / from the backpack to the deck causes simmilar behaviour.

Steps to Reproduce

  1. Open backpack
  2. Open task Manager to monitor RAM usage
  3. Show FrameRate (in the newest version by pressing 'T', or using the logger)
  4. Swap cards in the deck until the behaviour is observed. This happens more quickly if there a lot of cards in the backpack/deck.

Possible fix

The backpack should create each card only once and reuse them. When a screen transition occurs, the backpack should dispose the created cards. Sorting/swapping cards should only rearrange them and not regenerate them.

Version

tested in dev and b240207

GreenUserBlue commented 6 months ago

the source of the problem is different, "card in the deck, generating a new texture each time" is wrong, since it only access the cards which were previously generated at the end of the "init" method