Skip to content

Instantly share code, notes, and snippets.

@eilo
Created December 28, 2012 04:57
Show Gist options
  • Save eilo/4394652 to your computer and use it in GitHub Desktop.
Save eilo/4394652 to your computer and use it in GitHub Desktop.
IntersectRay crashfix patchfile
From f4c741dfccbd270c669bf7e4f9b5f7c4a745d00f Mon Sep 17 00:00:00 2001
From: Eilo <[email protected]>
Date: Thu, 27 Dec 2012 23:29:13 -0500
Subject: [PATCH] Core/Model: Fix crashes on IntersectRay, original patch and idea by MrSmite
---
src/server/collision/BoundingIntervalHierarchy.h | 3 +++
src/server/collision/Models/GameObjectModel.cpp | 16 +++++++++-------
src/server/collision/Models/WorldModel.cpp | 10 +++++++---
4 files changed, 20 insertions(+), 10 deletions(-)
########################
diff --git a/src/server/collision/BoundingIntervalHierarchy.h b/src/server/collision/BoundingIntervalHierarchy.h
index a4bbe21..2d6e3c7 100755
--- a/src/server/collision/BoundingIntervalHierarchy.h
+++ b/src/server/collision/BoundingIntervalHierarchy.h
@@ -350,6 +350,9 @@ class BIH
bool writeToFile(FILE* wf) const;
bool readFromFile(FILE* rf);
+ bool IsTreeEmpty() const { return tree.empty(); }
+ bool IsObjectsEmpty() const { return objects.empty(); }
+
protected:
std::vector<uint32> tree;
std::vector<uint32> objects;
diff --git a/src/server/collision/Models/GameObjectModel.cpp b/src/server/collision/Models/GameObjectModel.cpp
index d8c3992..c29aa7f 100644
--- a/src/server/collision/Models/GameObjectModel.cpp
+++ b/src/server/collision/Models/GameObjectModel.cpp
@@ -175,13 +175,15 @@ bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool Sto
Vector3 p = iInvRot * (ray.origin() - iPos) * iInvScale;
Ray modRay(p, iInvRot * ray.direction());
float distance = MaxDist * iInvScale;
- bool hit = iModel->IntersectRay(modRay, distance, StopAtFirstHit);
- if (hit)
- {
- distance *= iScale;
- MaxDist = distance;
- }
- return hit;
+
+ if (iModel)
+ if (iModel->IntersectRay(modRay, distance, StopAtFirstHit))
+ {
+ distance *= iScale;
+ MaxDist = distance;
+ return true;
+ }
+ return false;
}
#endif
diff --git a/src/server/collision/Models/WorldModel.cpp b/src/server/collision/Models/WorldModel.cpp
index b4f3f73..356b7c4 100644
--- a/src/server/collision/Models/WorldModel.cpp
+++ b/src/server/collision/Models/WorldModel.cpp
@@ -425,9 +425,13 @@ namespace VMAP
if (groupModels.size() == 1)
return groupModels[0].IntersectRay(ray, distance, stopAtFirstHit);
- WModelRayCallBack isc(groupModels);
- groupTree.intersectRay(ray, isc, distance, stopAtFirstHit);
- return isc.hit;
+ if (!groupTree.IsObjectsEmpty() && !groupTree.IsTreeEmpty())
+ {
+ WModelRayCallBack isc(groupModels);
+ groupTree.intersectRay(ray, isc, distance, stopAtFirstHit);
+ return isc.hit;
+ }
+ return false;
}
class WModelAreaCallback {
--
1.7.11.msysgit.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment