NJSADFNSDFNSFDN
NJSADFNSDFNSFDN

Reputation: 11

C++/SDL2 IMG_Load Error (Out of memory)

I am making a shoot'em up game and have been coming into a problem where the sprites won't load at all after a certain amount of time and continuously shooting. In my console, an error prints out:

"IMG_LOAD_ERROR : Out of memory" (The "IMG_LOAD_ERROR : " was my own thing)

I also use text (SDL_ttf) to display an ammo count.

The hypothesis I have now is that I always call the IMG_load function in the constructor of every enemy that is spawned, but I'm not even sure if that's what's causing it. There are quite a few more possibilities I can think of.

Also, I do free the textures when they are destroyed (when the enemy is out of health or leaves the screen).

Can someone help me understand this and help me fix it?

Upvotes: 0

Views: 1242

Answers (1)

OrdinaryNick
OrdinaryNick

Reputation: 248

It seems that you are not destroying textures/images or renderes that you are not need.

SDL_DestroyTexture(img); SDL_DestroyRenderer(renderer);

Simple example of drawing image, which i found https://gist.github.com/armornick/3434362.

My advice: You should load all textures or begin of application or when is needed, but it must be once. You must reuse every same image.

It would be nice to see code to find out, what is wrong with code.

Upvotes: 2

Related Questions