What’s happening is if I load 2 textures or more in a row it gives me reading access violation.
When I’m loading a texture or TTF in SDL what I do is the following:
//If there is a texture, destroy it and set to NULL
freeTexture(texture);
SDL_Surface* loadedSurface = TTF_RenderText_Solid(font, textureText, textColor);
if (loadedSurface == NULL)
{
printf("Unable to render Solid Text! Error: %s\n", TTF_GetError());
}
else
{
texture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
if (texture == NULL)
{
printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError());
}
else
{
size.x = loadedSurface->w;
size.y = loadedSurface->h;
}
SDL_FreeSurface(loadedSurface)
}
I resolved it by creating one surface to load the images inside the structure that I use to handle the textures, so what I do is check if it’s different from NULL before loading something, and if it is, I free the surface and make it NULL.
After that the error has stopped. What I don’t understand is why freeing a simple surface that was used only for a simple loading, was causing to the next call to the function a memory reading violation.