Skip to content

Fix SphereBVHNode::checkCollision null deref crash on leaf nodes#235

Merged
FriedricNietzsche merged 2 commits into
191-pbr-ibl-ambient-lightingfrom
copilot/sub-pr-230-another-one
Mar 16, 2026
Merged

Fix SphereBVHNode::checkCollision null deref crash on leaf nodes#235
FriedricNietzsche merged 2 commits into
191-pbr-ibl-ambient-lightingfrom
copilot/sub-pr-230-another-one

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 16, 2026

The const overload of SphereBVHNode::checkCollision unconditionally dereferenced left and right without an isLeaf() guard or null checks, causing a guaranteed crash when traversal reached any leaf node.

Changes

  • Fix const checkCollision — rewritten to match correct traversal logic:
    • dynamic_cast guard for non-sphere colliders
    • Bounding sphere overlap test before recursion
    • isLeaf() early-out returning sphere.checkCollision(...) directly
    • Null-guarded recursive calls on left/right
bool SphereBVHNode::checkCollision(const Collider& collider, std::vector<ContactInfo>& info) const {
    const auto* otherSphere = dynamic_cast<const SphereCollider*>(&collider);
    if (!otherSphere) return false;

    if (!spheresOverlap(sphere, *otherSphere)) return false;

    if (isLeaf()) return sphere.checkCollision(*otherSphere, info);

    bool hitLeft  = left  ? left->checkCollision(collider, info)  : false;
    bool hitRight = right ? right->checkCollision(collider, info) : false;
    return hitLeft || hitRight;
}
  • Removed non-const overload — not declared in the header; the fixed const version now subsumes it
  • Removed duplicate isLeaf() definition and stray dead code (orphaned buildRecursive fragment) outside the closing namespace brace
  • Reordered spheresOverlap to appear before checkCollision to fix declaration order

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: FriedricNietzsche <142739679+FriedricNietzsche@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on IBL ambient lighting integration in PBR shader Fix SphereBVHNode::checkCollision null deref crash on leaf nodes Mar 16, 2026
Copilot AI requested a review from FriedricNietzsche March 16, 2026 22:19
@FriedricNietzsche FriedricNietzsche marked this pull request as ready for review March 16, 2026 22:22
@FriedricNietzsche FriedricNietzsche merged commit 2993a5e into 191-pbr-ibl-ambient-lighting Mar 16, 2026
@FriedricNietzsche FriedricNietzsche deleted the copilot/sub-pr-230-another-one branch March 16, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants