Skip to content

Commit

Permalink
fix: improved safety to prevent crashing caused by raycast
Browse files Browse the repository at this point in the history
  • Loading branch information
SaneEngineer committed Jun 13, 2024
1 parent 4eb30f7 commit 6a9712e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/RaycastHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ Raycast::RayResult Raycast::hkpCastRay(const glm::vec4& start, const glm::vec4&
pickData.rayHitCollectorA8 = reinterpret_cast<RE::hkpClosestRayHitCollector*>(collector);

const auto ply = RE::PlayerCharacter::GetSingleton();
if (!ply->parentCell)
auto cell = ply->GetParentCell();
if (!cell)
return {};

if (ply->loadedData && ply->loadedData->data3D)
Expand All @@ -121,12 +122,15 @@ Raycast::RayResult Raycast::hkpCastRay(const glm::vec4& start, const glm::vec4&

RayResult result;

auto physicsWorld = ply->parentCell->GetbhkWorld();
if (physicsWorld) {
//physicsWorld->PickObject(pickData);
if (physicsWorld->PickObject(pickData); pickData.rayOutput.HasHit()) {
result.CollisionLayer = static_cast<RE::COL_LAYER>(pickData.rayOutput.rootCollidable->broadPhaseHandle.collisionFilterInfo & 0x7F);
try {
auto physicsWorld = cell->GetbhkWorld();
if (physicsWorld) {
//physicsWorld->PickObject(pickData);
if (physicsWorld->PickObject(pickData); pickData.rayOutput.HasHit()) {
result.CollisionLayer = static_cast<RE::COL_LAYER>(pickData.rayOutput.rootCollidable->broadPhaseHandle.collisionFilterInfo & 0x7F);
}
}
} catch (...) {
}

result.hitArray = collector->GetHits();
Expand Down

0 comments on commit 6a9712e

Please sign in to comment.