Merge pull request #15635 from AndrewMeadows/fix-bugz-164

BUGZ-164: fix crash when processing physics simulation ownership bids
This commit is contained in:
Brad Hefta-Gaub 2019-05-28 12:59:07 -07:00 committed by GitHub
commit cea40af23a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -6401,6 +6401,7 @@ void Application::update(float deltaTime) {
PerformanceTimer perfTimer("simulation"); PerformanceTimer perfTimer("simulation");
getEntities()->preUpdate(); getEntities()->preUpdate();
_entitySimulation->removeDeadEntities();
auto t0 = std::chrono::high_resolution_clock::now(); auto t0 = std::chrono::high_resolution_clock::now();
auto t1 = t0; auto t1 = t0;

View file

@ -214,15 +214,26 @@ void PhysicalEntitySimulation::clearEntitiesInternal() {
_entitiesToRemoveFromPhysics.clear(); _entitiesToRemoveFromPhysics.clear();
_entitiesToAddToPhysics.clear(); _entitiesToAddToPhysics.clear();
_incomingChanges.clear(); _incomingChanges.clear();
_entitiesToDeleteLater.clear();
} }
// virtual // virtual
void PhysicalEntitySimulation::prepareEntityForDelete(EntityItemPointer entity) { void PhysicalEntitySimulation::prepareEntityForDelete(EntityItemPointer entity) {
// this can be called on any thread
assert(entity); assert(entity);
assert(entity->isDead()); assert(entity->isDead());
QMutexLocker lock(&_mutex); QMutexLocker lock(&_mutex);
_entitiesToDeleteLater.push_back(entity);
}
void PhysicalEntitySimulation::removeDeadEntities() {
// only ever call this on the main thread
QMutexLocker lock(&_mutex);
for (auto& entity : _entitiesToDeleteLater) {
entity->clearActions(getThisPointer()); entity->clearActions(getThisPointer());
removeEntityInternal(entity); removeEntityInternal(entity);
}
_entitiesToDeleteLater.clear();
} }
// end EntitySimulation overrides // end EntitySimulation overrides

View file

@ -80,6 +80,7 @@ protected: // only called by EntitySimulation
public: public:
virtual void prepareEntityForDelete(EntityItemPointer entity) override; virtual void prepareEntityForDelete(EntityItemPointer entity) override;
void removeDeadEntities();
void buildPhysicsTransaction(PhysicsEngine::Transaction& transaction); void buildPhysicsTransaction(PhysicsEngine::Transaction& transaction);
void handleProcessedPhysicsTransaction(PhysicsEngine::Transaction& transaction); void handleProcessedPhysicsTransaction(PhysicsEngine::Transaction& transaction);
@ -121,6 +122,7 @@ private:
VectorOfEntityMotionStates _owned; VectorOfEntityMotionStates _owned;
VectorOfEntityMotionStates _bids; VectorOfEntityMotionStates _bids;
SetOfEntities _deadAvatarEntities; SetOfEntities _deadAvatarEntities;
std::vector<EntityItemPointer> _entitiesToDeleteLater;
workload::SpacePointer _space; workload::SpacePointer _space;
uint64_t _nextBidExpiry; uint64_t _nextBidExpiry;
uint32_t _lastStepSendPackets { 0 }; uint32_t _lastStepSendPackets { 0 };