Merge pull request #13411 from sabrina-shanman/crash-delete-cube

Fix crash when deleting objects in serverless mode
This commit is contained in:
John Conklin II 2018-06-21 14:39:07 -07:00 committed by GitHub
commit 4088035b3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 18 deletions

View file

@ -339,7 +339,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
if (_numInactiveUpdates > 0) {
const uint8_t MAX_NUM_INACTIVE_UPDATES = 20;
if (_numInactiveUpdates > MAX_NUM_INACTIVE_UPDATES || isServerlessMode()) {
if (_numInactiveUpdates > MAX_NUM_INACTIVE_UPDATES) {
// clear local ownership (stop sending updates) and let the server clear itself
_entity->clearSimulationOwnership();
return false;
@ -834,9 +834,3 @@ void EntityMotionState::clearObjectVelocities() const {
}
_entity->setAcceleration(glm::vec3(0.0f));
}
bool EntityMotionState::isServerlessMode() {
EntityTreeElementPointer element = _entity->getElement();
EntityTreePointer tree = element ? element->getTree() : nullptr;
return tree ? tree->isServerlessMode() : false;
}

View file

@ -306,12 +306,15 @@ void PhysicalEntitySimulation::getObjectsToChange(VectorOfMotionStates& result)
}
void PhysicalEntitySimulation::handleDeactivatedMotionStates(const VectorOfMotionStates& motionStates) {
bool serverlessMode = getEntityTree()->isServerlessMode();
for (auto stateItr : motionStates) {
ObjectMotionState* state = &(*stateItr);
assert(state);
if (state->getType() == MOTIONSTATE_TYPE_ENTITY) {
EntityMotionState* entityState = static_cast<EntityMotionState*>(state);
entityState->handleDeactivation();
if (!serverlessMode) {
entityState->handleDeactivation();
}
EntityItemPointer entity = entityState->getEntity();
_entitiesToSort.insert(entity);
}
@ -357,13 +360,7 @@ void PhysicalEntitySimulation::handleChangedMotionStates(const VectorOfMotionSta
}
void PhysicalEntitySimulation::addOwnershipBid(EntityMotionState* motionState) {
if (getEntityTree()->isServerlessMode()) {
EntityItemPointer entity = motionState->getEntity();
auto nodeList = DependencyManager::get<NodeList>();
auto sessionID = nodeList->getSessionUUID();
entity->setSimulationOwner(SimulationOwner(sessionID, SCRIPT_GRAB_SIMULATION_PRIORITY));
_owned.push_back(motionState);
} else {
if (!getEntityTree()->isServerlessMode()) {
motionState->initForBid();
motionState->sendBid(_entityPacketSender, _physicsEngine->getNumSubsteps());
_bids.push_back(motionState);
@ -372,8 +369,10 @@ void PhysicalEntitySimulation::addOwnershipBid(EntityMotionState* motionState) {
}
void PhysicalEntitySimulation::addOwnership(EntityMotionState* motionState) {
motionState->initForOwned();
_owned.push_back(motionState);
if (!getEntityTree()->isServerlessMode()) {
motionState->initForOwned();
_owned.push_back(motionState);
}
}
void PhysicalEntitySimulation::sendOwnershipBids(uint32_t numSubsteps) {
@ -412,6 +411,7 @@ void PhysicalEntitySimulation::sendOwnershipBids(uint32_t numSubsteps) {
}
void PhysicalEntitySimulation::sendOwnedUpdates(uint32_t numSubsteps) {
bool serverlessMode = getEntityTree()->isServerlessMode();
PROFILE_RANGE_EX(simulation_physics, "Update", 0x00000000, (uint64_t)_owned.size());
uint32_t i = 0;
while (i < _owned.size()) {
@ -423,7 +423,7 @@ void PhysicalEntitySimulation::sendOwnedUpdates(uint32_t numSubsteps) {
}
_owned.remove(i);
} else {
if (_owned[i]->shouldSendUpdate(numSubsteps)) {
if (!serverlessMode && _owned[i]->shouldSendUpdate(numSubsteps)) {
_owned[i]->sendUpdate(_entityPacketSender, numSubsteps);
}
++i;