SDL_TEXTURE high memory usage

Hi Everyone,

I'm programming a 2D Game usign SDL_2.0 and I'm having an issue with SDL_Texture.

All my textures are loaded once in my Main.h and then my other classes define objects that all have SDL_Texture* Members , ranging from 1 to more (like 6).

The problem is that even if all my class SDL_Texture* members are pointers, it seems like a new copy of the SDL_Texture pointed at is created every time I create a new Object in my Vectors.

I use SDL_RenderCopy to render my images and I have one Static SDL_Renderer object declared in a Parent Class.

Do you have nay idea what I can do to solve this issue?

The game im creating is an fully randomized open world rpg and when i create a larger world I go up to almost 2 gigs of used RAM and the game crashes at some point late in world generation.

Now im running on a small world and it works, but i'm at 200 megs and its a very small world. It's Not normal. I'm running on a 9 biome world of 40000 objects each. And each objects points to a texture of on average 12 KB.


Thank guys.
Creating an object should not imply creating a texture. The actions of loading a texture and of assigning a texture to an object should be distinct.
What you need is a resource manager that can keep track of which resources have already been loaded into textures, so that when an object requests a texture of a given resource, the manager can decide between returning a pointer to an existing texture or loading the resource and returning a pointer to the new texture. Additionally, you should wrap the textures in reference-counted Resource objects, so that the manager can be notified when the last usage of a resource is released.
Topic archived. No new replies allowed.