[FIX] Create dummy SceneEntity for unused SceneMeshes #1410
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.
This PR changes the way
SceneModel
handlesSceneMesh
instances that are not used by anySceneEntity
instances.We cannot have
SceneMesh
instances that are not used bySceneEntities
, because that throws certain renderer counters out of whack.If we create meshes with
SceneModel.createMesh()
but don't actually use those meshes withSceneModel.createEntity()
, then we end up with internal counters (numVisible, numHighlighted etc) becoming incorrect.This is because certain internal counts are initialised by
SceneModel.createMesh()
, independently of whetherSceneModel.createEntity()
is ever called.We fixed this in #1336 by making
SceneModel
buffer the parameters for eachSceneModel.createMesh()
, without immediately creating theSceneMesh
, then created theSceneMesh
inSceneModel.createEntity()
, only if thatSceneMesh
was used by theSceneEntity
.This created an undesirable memory spike in
SceneModel.finalize()
for large models.We therefore undo that fix (#1336) with this PR and make a better fix that does not create a memory spike.
After this PR
This PR restores
SceneModel
to its original behaviour of makingSceneModel.createMesh()
create theSceneMesh
immediately, but this timeSceneModel.finalize()
will create a dummySceneEntity
that owns all unusedSceneMesh
instances, and logs a warning.The following example illustrates this.
We create a SceneModel with two extra
SceneMeshes
, which are copies of one of the yellow table leg and the purple table top, each offset downloads on the Y-axis to separate them visually. A warning is logged in the console, and a dummySceneEntity
is created in theSceneModel
to claim them.