summaryrefslogtreecommitdiff
path: root/core/math/bvh_tree.h
diff options
context:
space:
mode:
authorlawnjelly <lawnjelly@gmail.com>2021-05-29 18:03:43 +0100
committerlawnjelly <lawnjelly@gmail.com>2021-05-29 18:03:43 +0100
commitbd42de5fea718ed6bf680dddbb8d823dd6760b68 (patch)
treefc40a8db10c5c6764d3cf7bbd7b42b5bdc922f0b /core/math/bvh_tree.h
parentb63f9b59615a4a63f1a45564d78243a2929c3c03 (diff)
BVH - fix stale current_tree in deactivate function [4.x]
Changes passing of current_tree from a member variable to a function argument, making bugs due to stale state less likely. Fix a bug in deactivate where current_tree variable was stale. This may have resulted in visual anomalies.
Diffstat (limited to 'core/math/bvh_tree.h')
-rw-r--r--core/math/bvh_tree.h15
1 files changed, 7 insertions, 8 deletions
diff --git a/core/math/bvh_tree.h b/core/math/bvh_tree.h
index 64c5f6e254..3169d31ec7 100644
--- a/core/math/bvh_tree.h
+++ b/core/math/bvh_tree.h
@@ -196,7 +196,7 @@ private:
new_child.parent_id = p_parent_id;
}
- void node_remove_child(uint32_t p_parent_id, uint32_t p_child_id, bool p_prevent_sibling = false) {
+ void node_remove_child(uint32_t p_parent_id, uint32_t p_child_id, uint32_t p_tree_id, bool p_prevent_sibling = false) {
TNode &parent = _nodes[p_parent_id];
BVH_ASSERT(!parent.is_leaf());
@@ -231,7 +231,7 @@ private:
if (grandparent_id == BVHCommon::INVALID) {
if (sibling_present) {
// change the root node
- change_root_node(sibling_id);
+ change_root_node(sibling_id, p_tree_id);
// delete the old root node as no longer needed
_nodes.free(p_parent_id);
@@ -243,16 +243,15 @@ private:
if (sibling_present) {
node_replace_child(grandparent_id, p_parent_id, sibling_id);
} else {
- node_remove_child(grandparent_id, p_parent_id, true);
+ node_remove_child(grandparent_id, p_parent_id, p_tree_id, true);
}
// put the node on the free list to recycle
_nodes.free(p_parent_id);
}
- // this relies on _current_tree being accurate
- void change_root_node(uint32_t p_new_root_id) {
- _root_node_id[_current_tree] = p_new_root_id;
+ void change_root_node(uint32_t p_new_root_id, uint32_t p_tree_id) {
+ _root_node_id[p_tree_id] = p_new_root_id;
TNode &root = _nodes[p_new_root_id];
// mark no parent
@@ -272,7 +271,7 @@ private:
node.neg_leaf_id = -(int)child_leaf_id;
}
- void node_remove_item(uint32_t p_ref_id, BVHABB_CLASS *r_old_aabb = nullptr) {
+ void node_remove_item(uint32_t p_ref_id, uint32_t p_tree_id, BVHABB_CLASS *r_old_aabb = nullptr) {
// get the reference
ItemRef &ref = _refs[p_ref_id];
uint32_t owner_node_id = ref.tnode_id;
@@ -336,7 +335,7 @@ private:
uint32_t parent_id = tnode.parent_id;
- node_remove_child(parent_id, owner_node_id);
+ node_remove_child(parent_id, owner_node_id, p_tree_id);
refit_upward(parent_id);
// put the node on the free list to recycle