Fix a bug in QuadtreePrimitive.forEachLoadedTile
#2155
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.
When moving the camera around quickly, it is possible to end up with terrain tiles in the replacement queue that haven't had any loading done on them at all. That is, they're in the
START
state instead of theLOADING
state. Specifically this happens when there are more tiles in the load queue than can be processed in the current frame.This change makes it so such tiles are no longer returned by
QuadtreePrimitive.forEachLoadedTile
since they are (arguably) not actually loaded. This fixes a few crashes I saw in the wild, mostly when adding and removing layers, because code callingforEachLoadedTile
wasn't expecting to to see tiles in theSTART
state. Originally I was just going to fix the place that made this incorrect assumption, but after I fixed the third such place I realized I'd be better off just avoiding the problem entirely.Fixes TerriaJS/nationalmap#358.