Description
openedon Sep 30, 2024
The change here for purge() to not return the iterator returned by std::vector::erase() is a bug. Consider std::vector::erase()'s contract:
"Iterators (including the end() iterator) and references to the elements at or after the point of the erase are invalidated."
The key thing here is the "elements AT or after the point of the erase" part. So in this case because purge() calls erase(it), "it" is invalid after the call. This is why the old code used the result from erase() -- it returns the next iterator after the one that was invalidated by erasing it.
Now, this code happens to work in release builds because obviously with a linear vector the next iterator really is going to point to the same element that was erased. But at least on MSVC in debug mode, it keeps track of the fact that erase() has invalidated the iterator and the program crashes here with "Expression: vector iterators incompatible." MSVC in debug mode is being quite pedantic, but it's technically correct, and anyway the practical outcome is that Filament crashes immediately in MSVC debug builds.