[core] Move objectStore in {GL,TexturePool}Holder::reset()

Fixes an issue where a moved {GL,TexturePool}Holder would use an invalid
pointer when accessing 'objectStore'.

Fixes #5136.
This commit is contained in:
Bruno de Oliveira Abinader
2016-05-25 23:53:43 +03:00
parent 26a425fa6d
commit b2b2797c2a
2 changed files with 10 additions and 11 deletions

View File

@@ -61,12 +61,11 @@ void TexturePoolHolder::create(GLObjectStore& objectStore_) {
void TexturePoolHolder::reset() {
if (!bool()) return;
for (GLuint id : ids) {
if (id) {
objectStore->abandonedTextures.push_back(id);
}
}
ids.fill(0);
for (GLuint& id : ids) {
if (id == 0) continue;
objectStore->abandonedTextures.push_back(id);
id = 0;
};
}
void VAOHolder::create(GLObjectStore& objectStore_) {

View File

@@ -38,8 +38,8 @@ class GLHolder : private util::noncopyable {
public:
GLHolder() {}
GLHolder(GLHolder&& o) noexcept : id(o.id) { o.id = 0; }
GLHolder& operator=(GLHolder&& o) noexcept { id = o.id; o.id = 0; return *this; }
GLHolder(GLHolder&& o) noexcept : id(o.id), objectStore(o.objectStore) { o.id = 0; }
GLHolder& operator=(GLHolder&& o) noexcept { id = o.id; objectStore = o.objectStore; o.id = 0; return *this; }
explicit operator bool() const { return id; }
GLuint getID() const { return id; }
@@ -107,10 +107,10 @@ public:
TexturePoolHolder() { ids.fill(0); }
~TexturePoolHolder() { reset(); }
TexturePoolHolder(TexturePoolHolder&& o) noexcept : ids(std::move(o.ids)) {}
TexturePoolHolder& operator=(TexturePoolHolder&& o) noexcept { ids = std::move(o.ids); return *this; }
TexturePoolHolder(TexturePoolHolder&& o) noexcept : ids(std::move(o.ids)), objectStore(o.objectStore) { o.ids.fill(0); }
TexturePoolHolder& operator=(TexturePoolHolder&& o) noexcept { ids = std::move(o.ids); objectStore = o.objectStore; o.ids.fill(0); return *this; }
explicit operator bool() { return std::none_of(ids.begin(), ids.end(), [](int id) { return id == 0; }); }
explicit operator bool() const { return std::any_of(ids.begin(), ids.end(), [](int id) { return id; }); }
const std::array<GLuint, TextureMax>& getIDs() const { return ids; }
const GLuint& operator[](size_t pos) { return ids[pos]; }