Fix potential crashes with TileMap navmesh baking #83891
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.
Fixes potential crashes with TileMap navmesh baking.
I discovered this because a user send me a project that crashed on a large TileMap when baking a navigation mesh from it.
Turned out it was not the size in quantity of the cells that was crashing it. The parsing crashed due to calling size() with empty TileData which resulted in the TileSet index macro causing a CowData nullptr crash when calling navigation.size().
The reason the loop was even running was because the used cells count was not updated after TileMap.clear(). The TileMap reporting the wrong used cell count after clear() is fixed with #83890.
So this pr now guards the parsing process against empty TileData or empty / zero-sized outline arrays.
Also improves performance slightly for complex polygons by switching to ptr() / ptrw().