avoid calling removeOwnershipData() from multiple threads

This commit is contained in:
Andrew Meadows 2019-05-24 16:12:01 -07:00
parent 9b26f70e2f
commit 5988f8cce6
3 changed files with 15 additions and 2 deletions

View file

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

View file

@ -218,11 +218,21 @@ void PhysicalEntitySimulation::clearEntitiesInternal() {
// virtual
void PhysicalEntitySimulation::prepareEntityForDelete(EntityItemPointer entity) {
// this can be called on any thread
assert(entity);
assert(entity->isDead());
QMutexLocker lock(&_mutex);
entity->clearActions(getThisPointer());
removeEntityInternal(entity);
_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());
removeEntityInternal(entity);
}
_entitiesToDeleteLater.clear();
}
// end EntitySimulation overrides

View file

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