diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-05-25 23:53:43 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-05-26 19:36:51 +0300 |
commit | b2b2797c2a30b8085683935d760c45284c639e96 (patch) | |
tree | fb77b91126b4d6808d00ebadae89bbed08d9df27 /src/mbgl/gl | |
parent | 26a425fa6d0386aa59027b1b5813edd781f460ed (diff) | |
download | qtlocation-mapboxgl-b2b2797c2a30b8085683935d760c45284c639e96.tar.gz |
[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.
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/gl_object_store.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/gl/gl_object_store.hpp | 10 |
2 files changed, 10 insertions, 11 deletions
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<GLuint, TextureMax>& getIDs() const { return ids; } const GLuint& operator[](size_t pos) { return ids[pos]; } |