Avoid indexing instances without a base in scene cull phase #95503
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: #95466
Fixes: #92615
Fixes: #80749
Fixes: #69258
Fixes: #80504
Supersedes: #81069
At the core, this crash happens because an instance without a base is added to one of our BVHs and then we try to operate on that instance in the other BVH.
There are 2 main ways this crash occurs:
VOLUME
BVH instead of theGEOMETRY
BVH. And so the engine crashes when it tries to update the instance in theGEOMETRY
BVH later.In both cases, the problem comes from the fact that the instance is added to the
VOLUME
BVH. The logic is: if an object is aGEOMETRY
type, it goes in theGEOMETRY
BVH, otherwise it goes into theVOLUME
BVH.When we go to set the base of an instance, the logic is: if the previous base type is not
NONE
then remove the instance from the BVH and clear all data. If the base type isNONE
we are assuming it was never added to a BVH. However, that assumption is false.This PR fixes the bug by making that assumption true. It adds an early out to
_update_instance
to ensure that when the base type is NONE, we don't add the instance to a BVH. This change is low risk since the instance gets queued for update again once the base type is set. Without a base, the instance can't do anything. So its safe to skip the pairing/indexing step when the base has not been assigned.The solution proposed by jsjtxietian in #81069 appears to work well for the Sprite3D case. It moves the instance from the
VOLUME
BVH to theGEOMETRY
BVH if the base changes fromNONE
toGEOMETRY
. However, it doesn't solve the other cases of the crash.CC @jsjtxietian