I’ve got a bit of demo code available. But the basic jist is that if I attempt to load a large directory of 900+ images, SDL will run “out of memory” eventually at some point while it’s iterating. However if I destroy the texture after creating it, everything works fine.
Was wondering if someone knew what might be causing this? IS there some texture cap that I’m unaware of? thanks!
std::vector<SDL_Texture*> textures;
for (auto folder : folders)
{
std::vector<std::string> filesToLoad;
for (auto& entry : std::filesystem::recursive_directory_iterator(this->getAssetPath() + folder))
{
auto name = entry.path().stem().string();
auto extension = entry.path().extension().string();
if (extension == ".png")
{
auto path = entry.path();
if (this->textures.count(path) == 0)
{
filesToLoad.push_back(path.string());
}
}
}
for (auto strPath : filesToLoad)
{
auto surface = IMG_Load(strPath.c_str());
if (surface)
{
auto renderer = GraphClass::Instance()->getRenderer();
auto texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
if (texture)
{
//SDL_DestroyTexture(texture); //doesn't cause a crash
textures.push_back(texture); //causes a crash
}
else
{
printf(SDL_GetError() + '\n');
}
}
else
{
printf(SDL_GetError() + '\n');
}
}
}