-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix texture leak in TexturePoolHolder #5141
Conversation
} | ||
} | ||
ids.fill(0); | ||
std::for_each(ids.begin(), ids.end(), [&](GLuint& id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the switch from range-based for
to for_each
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I can achieve the same thing capturing a non-const reference in a range-based for
.
dc597ef
to
0b7277b
Compare
The intended invariant is that if I think the actual bug lies in the implementations of the move constructors and |
Here's how I would do if implementing this pattern from scratch:
|
0b7277b
to
b9351dd
Compare
@jfirebaugh my previous implementation used |
ids.fill(0); | ||
if (!created()) return; | ||
for (GLuint& id : ids) { | ||
if (id == 0) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return
needs to revert back to a conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, meant continue
there.
b9351dd
to
78a26b7
Compare
@@ -38,10 +38,10 @@ 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) { id = 0; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change o.id = 0
to id = 0
? Isn't the former correct?
Fixes an issue where a moved {GL,TexturePool}Holder would use an invalid pointer when accessing 'objectStore'. Fixes #5136.
Prevents confusing usage of GL holder objects.
78a26b7
to
c111250
Compare
We'll proceed with @jfirebaugh's suggestion from #5141 (comment) in a separate PR. |
Source: https://github.com/okdshin/unique_resource These replace the complexity of manually handling moveable-RAII objects with a type specific for that purpose. As suggested in #5141 (comment).
Source: https://github.com/okdshin/unique_resource These replace the complexity of manually handling moveable-RAII objects with a type specific for that purpose. As suggested in #5141 (comment).
Source: https://github.com/okdshin/unique_resource These replace the complexity of manually handling moveable-RAII objects with a type specific for that purpose. As suggested in #5141 (comment).
Source: https://github.com/okdshin/unique_resource These replace the complexity of manually handling moveable-RAII objects with a type specific for that purpose. As suggested in #5141 (comment).
Hey @jfirebaugh, i came across this recently and was wondering if you would still do it this way.
Why is the unique_resource.hpp needed? Would love to understand this, i am probably missing something! |
@haberbyte |
Ah, that makes sense, thank you! Unfortunate, that it is not even part of C++17 🤷♂ |
Fixes a misused
operator bool()
plus usage of an undefined pointer in{GL,TexturePool}Holder
code.👀 @kkaefer @jfirebaugh
Fixes #5136.