Fix crash when loading more than 16 vector layers #51782
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This fixes another unreported regression introduced by #50381. QGIS would crash when trying to load more than 16 vector layers at once.
This was caused by an ambiguous sorting rule passed to
std::sort()
for sorting vector layers based on their geometry type, which would cause the sorting algorithm to try to read past the list's last element.Sorting 16 or less layers would not crash as
std::sort()
uses a different sorting algorithm for small lists.Also, fixes proper ordering for multipolygons/multisurface/curvepolygons:
![image](https://user-images.githubusercontent.com/11358178/217796424-e5c22ca6-8841-4cae-9341-7d3c2aa94216.png)
Before:
After:
![image](https://user-images.githubusercontent.com/11358178/217796487-21c927f4-73ad-449c-82a2-d1b29d36f3d9.png)
Kudos to @wonder-sk for tracking this down!