summaryrefslogtreecommitdiff
path: root/gfx/gl/instanceVertices.h
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/instanceVertices.h')
-rw-r--r--gfx/gl/instanceVertices.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h
index edcaef4..51bf4bc 100644
--- a/gfx/gl/instanceVertices.h
+++ b/gfx/gl/instanceVertices.h
@@ -132,19 +132,22 @@ protected:
{
// Destroy p's object
at(pidx).~T();
- if (next-- > index[pidx]) {
- // Remember p.index is free index now
- unused.push_back(pidx);
+ if (--next != index[pidx]) {
// Move last object into p's slot
new (&at(pidx)) T {std::move(data[next])};
(data[next]).~T();
- *std::find(index.begin(), index.end(), next) = index[pidx];
- // Not strictly required, but needed for uniqueness unit test assertion
- index[pidx] = static_cast<size_t>(-1);
+ *std::find_if(index.begin(), index.end(), [this](const auto & i) {
+ const auto n = &i - index.data();
+ return i == next && std::find(unused.begin(), unused.end(), n) == unused.end();
+ }) = index[pidx];
}
- else {
+ if (pidx == index.size() - 1) {
index.pop_back();
}
+ else {
+ // Remember p.index is free index now
+ unused.push_back(pidx);
+ }
}
void