Skip to content

Commit

Permalink
fix iterator access issue when cleaning up textures
Browse files Browse the repository at this point in the history
  • Loading branch information
no-lex committed Oct 15, 2023
1 parent 2dcc05e commit 8759958
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
30 changes: 13 additions & 17 deletions src/engine/render/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2527,21 +2527,6 @@ Texture *Slot::loadthumbnail()

// environment mapped reflections

void Texture::cleanup()
{
delete[] alphamask;
alphamask = nullptr;
if(id)
{
glDeleteTextures(1, &id);
id = 0;
}
if(type&Texture::TRANSIENT)
{
textures.erase(name);
}
}

void cleanuptextures()
{
for(Slot * const &i : slots)
Expand All @@ -2560,9 +2545,20 @@ void cleanuptextures()
{
i->cleanup();
}
for(auto &[k, i] : textures)
for(auto itr = textures.begin(); itr != textures.end(); ++itr)
{
i.cleanup();
Texture &t = (*itr).second;
delete[] t.alphamask;
t.alphamask = nullptr;
if(t.id)
{
glDeleteTextures(1, &t.id);
t.id = 0;
}
if(t.type&Texture::TRANSIENT)
{
itr = textures.erase(itr);
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/engine/render/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ struct Texture

Texture() : alphamask(nullptr) {}
const uchar * loadalphamask();
void cleanup();
float ratio() const;
bool reload(); //if the texture does not have a valid GL texture, attempts to reload it

Expand Down

0 comments on commit 8759958

Please sign in to comment.