Merge pull request #7667 from AndrewMeadows/fix-entity-server-crash

fix entity-server crash when entity moves out of bounds
This commit is contained in:
Seth Alves 2016-04-18 14:09:21 -07:00
commit 4bf98a80b9
7 changed files with 22 additions and 11 deletions

View file

@ -926,7 +926,8 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
glm::quat dQ = computeBulletRotationStep(localAngularVelocity, dt);
rotation = glm::normalize(dQ * rotation);
setRotation(rotation);
bool success;
setOrientation(rotation, success, false);
}
setLocalAngularVelocity(localAngularVelocity);
@ -1983,10 +1984,10 @@ void EntityItem::locationChanged(bool tellPhysics) {
requiresRecalcBoxes();
if (tellPhysics) {
_dirtyFlags |= Simulation::DIRTY_TRANSFORM;
}
EntityTreePointer tree = getTree();
if (tree) {
tree->entityChanged(getThisPointer());
EntityTreePointer tree = getTree();
if (tree) {
tree->entityChanged(getThisPointer());
}
}
SpatiallyNestable::locationChanged(tellPhysics); // tell all the children, also
}

View file

@ -35,6 +35,7 @@ void EntitySimulation::updateEntities() {
callUpdateOnEntitiesThatNeedIt(now);
moveSimpleKinematics(now);
updateEntitiesInternal(now);
PerformanceTimer perfTimer("sortingEntities");
sortEntitiesThatMoved();
}
@ -133,10 +134,8 @@ void EntitySimulation::callUpdateOnEntitiesThatNeedIt(const quint64& now) {
// protected
void EntitySimulation::sortEntitiesThatMoved() {
QMutexLocker lock(&_mutex);
// NOTE: this is only for entities that have been moved by THIS EntitySimulation.
// External changes to entity position/shape are expected to be sorted outside of the EntitySimulation.
PerformanceTimer perfTimer("sortingEntities");
MovingEntitiesOperator moveOperator(_entityTree);
AACube domainBounds(glm::vec3((float)-HALF_TREE_SCALE), (float)TREE_SCALE);
SetOfEntities::iterator itemItr = _entitiesToSort.begin();

View file

@ -92,7 +92,7 @@ protected:
void expireMortalEntities(const quint64& now);
void callUpdateOnEntitiesThatNeedIt(const quint64& now);
void sortEntitiesThatMoved();
virtual void sortEntitiesThatMoved();
QMutex _mutex{ QMutex::Recursive };

View file

@ -132,3 +132,12 @@ void SimpleEntitySimulation::clearEntitiesInternal() {
_entitiesThatNeedSimulationOwner.clear();
}
void SimpleEntitySimulation::sortEntitiesThatMoved() {
SetOfEntities::iterator itemItr = _entitiesToSort.begin();
while (itemItr != _entitiesToSort.end()) {
EntityItemPointer entity = *itemItr;
entity->computePuffedQueryAACube();
++itemItr;
}
EntitySimulation::sortEntitiesThatMoved();
}

View file

@ -30,6 +30,8 @@ protected:
virtual void changeEntityInternal(EntityItemPointer entity) override;
virtual void clearEntitiesInternal() override;
virtual void sortEntitiesThatMoved() override;
SetOfEntities _entitiesWithSimulationOwner;
SetOfEntities _entitiesThatNeedSimulationOwner;
quint64 _nextOwnerlessExpiry { 0 };

View file

@ -620,7 +620,7 @@ glm::vec3 SpatiallyNestable::getLocalPosition() const {
return result;
}
void SpatiallyNestable::setLocalPosition(const glm::vec3& position) {
void SpatiallyNestable::setLocalPosition(const glm::vec3& position, bool tellPhysics) {
// guard against introducing NaN into the transform
if (isNaN(position)) {
qDebug() << "SpatiallyNestable::setLocalPosition -- position contains NaN";
@ -629,7 +629,7 @@ void SpatiallyNestable::setLocalPosition(const glm::vec3& position) {
_transformLock.withWriteLock([&] {
_transform.setTranslation(position);
});
locationChanged();
locationChanged(tellPhysics);
}
glm::quat SpatiallyNestable::getLocalOrientation() const {

View file

@ -102,7 +102,7 @@ public:
virtual void setLocalTransform(const Transform& transform);
virtual glm::vec3 getLocalPosition() const;
virtual void setLocalPosition(const glm::vec3& position);
virtual void setLocalPosition(const glm::vec3& position, bool tellPhysics = true);
virtual glm::quat getLocalOrientation() const;
virtual void setLocalOrientation(const glm::quat& orientation);