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

Author Topic: Question about textures and resources in general  (Read 1758 times)

0 Members and 1 Guest are viewing this topic.

JunkerKun

  • Newbie
  • *
  • Posts: 35
    • View Profile
Question about textures and resources in general
« on: June 14, 2018, 11:26:53 am »
Hello there.
It's been a long time since I used sfml and I redesigned my engine to not use pointers (at least I don't manage them manually) but I have a question. Let's say I load a texture that is used by several sprites. If I make a caching system by creating two sprites that use the same texture will it work? What I mean is will texture be deleted only when I delete all if the sprites and if at least one of them is alive and kicking the texture will be stored in memory? Or is there another better way of implementing caching?

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Question about textures and resources in general
« Reply #1 on: June 14, 2018, 02:25:30 pm »
You have to manage the texture lifetime yourself. The sprites has a non-owner pointer to the texture. So whenever the texture is deleted, those sprites will have a dangling pointer to the texture.

In your situation, you have to make sure your caching system remain alive as long as some sprite used the textures stored within. The lifetime of your sprites won't affect the lifetime of your textures.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

JunkerKun

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Question about textures and resources in general
« Reply #2 on: June 14, 2018, 11:55:19 pm »
Well, the idea was to keep sprites and textures in an array anyway, so I guess that could work...
Thanks!