From b2b2797c2a30b8085683935d760c45284c639e96 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 25 May 2016 23:53:43 +0300 Subject: [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. --- src/mbgl/gl/gl_object_store.cpp | 11 +++++------ src/mbgl/gl/gl_object_store.hpp | 10 +++++----- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/mbgl/gl') diff --git a/src/mbgl/gl/gl_object_store.cpp b/src/mbgl/gl/gl_object_store.cpp index 4948e20694..9646fb328e 100644 --- a/src/mbgl/gl/gl_object_store.cpp +++ b/src/mbgl/gl/gl_object_store.cpp @@ -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_) { diff --git a/src/mbgl/gl/gl_object_store.hpp b/src/mbgl/gl/gl_object_store.hpp index b30abd3892..9e0575046a 100644 --- a/src/mbgl/gl/gl_object_store.hpp +++ b/src/mbgl/gl/gl_object_store.hpp @@ -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& getIDs() const { return ids; } const GLuint& operator[](size_t pos) { return ids[pos]; } -- cgit v1.2.1