History

lock the entity tree during physics operations that access then entity tree. if the simulation and entity-tree are both going to be locked, be sure to lock the entity tree first (and unlock it last), because this is what the network-reading thread does

Seth Alves committed 11 years ago

Commit a0d77c01 parent 63812f23 files · +95 −22Browse files

Showing the changes to interface/src/Application.cpp (1 of 3 files). Show all

Unified · Split

interface/src/Application.cpp+21−0
@@ -2496,24 +2496,45 @@ void Application::update(float deltaTime) { · 2495 unmodified lines
24962496
24972497 _entitySimulation.lock();
24982498 _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete());
2499+ _entitySimulation.unlock();
2500+
2501+ _entities.getTree()->lockForWrite();
2502+ _entitySimulation.lock();
24992503 _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd());
2504+ _entitySimulation.unlock();
2505+ _entities.getTree()->unlock();
2506+
2507+ _entities.getTree()->lockForWrite();
2508+ _entitySimulation.lock();
25002509 _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange());
2510+ _entitySimulation.unlock();
2511+ _entities.getTree()->unlock();
2512+
2513+ _entitySimulation.lock();
25012514 _entitySimulation.applyActionChanges();
25022515 _entitySimulation.unlock();
25032516
2517+
25042518 AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();
25052519 _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete());
25062520 _physicsEngine.addObjects(avatarManager->getObjectsToAdd());
25072521 _physicsEngine.changeObjects(avatarManager->getObjectsToChange());
25082522
2523+ _entities.getTree()->lockForWrite();
25092524 _physicsEngine.stepSimulation();
2525+ _entities.getTree()->unlock();
25102526
25112527 if (_physicsEngine.hasOutgoingChanges()) {
2528+ _entities.getTree()->lockForWrite();
25122529 _entitySimulation.lock();
25132530 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());
25142531 _entitySimulation.unlock();
2532+ _entities.getTree()->unlock();
25152533
2534+ _entities.getTree()->lockForWrite();
25162535 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());
2536+ _entities.getTree()->unlock();
2537+
25172538 auto collisionEvents = _physicsEngine.getCollisionEvents();
25182539 avatarManager->handleCollisionEvents(collisionEvents);
25192540

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t