Application: don't call Model::simulate on network thread.

This can cause a crash.

On startup the Application::processOctreeStats method on the network thread will call into entities entity->isReadyToComputeShape() (without a tree lock) and trigger Model::simulate.  Model is NOT thread safe.  This was leading to a single model to be initialized on two threads simultaneously.

This might be somewhat rare, I only caught it because I was running a debug build.
This commit is contained in:
Anthony J. Thibault 2016-03-31 17:57:20 -07:00
parent 74633ca8c8
commit 3d43f73a88
2 changed files with 22 additions and 16 deletions

View file

@ -3215,6 +3215,25 @@ void Application::update(float deltaTime) {
updateLOD();
if (!_physicsEnabled && _processOctreeStatsCounter > 0) {
// process octree stats packets are sent in between full sends of a scene.
// We keep physics disabled until we've recieved a full scene and everything near the avatar in that
// scene is ready to compute its collision shape.
if (nearbyEntitiesAreReadyForPhysics()) {
_physicsEnabled = true;
getMyAvatar()->updateMotionBehaviorFromMenu();
} else {
auto characterController = getMyAvatar()->getCharacterController();
if (characterController) {
// if we have a character controller, disable it here so the avatar doesn't get stuck due to
// a non-loading collision hull.
characterController->setEnabled(false);
}
}
}
{
PerformanceTimer perfTimer("devices");
DeviceTracker::updateAll();
@ -4260,22 +4279,7 @@ int Application::processOctreeStats(ReceivedMessage& message, SharedNodePointer
});
});
if (!_physicsEnabled) {
if (nearbyEntitiesAreReadyForPhysics()) {
// These stats packets are sent in between full sends of a scene.
// We keep physics disabled until we've recieved a full scene and everything near the avatar in that
// scene is ready to compute its collision shape.
_physicsEnabled = true;
getMyAvatar()->updateMotionBehaviorFromMenu();
} else {
auto characterController = getMyAvatar()->getCharacterController();
if (characterController) {
// if we have a character controller, disable it here so the avatar doesn't get stuck due to
// a non-loading collision hull.
characterController->setEnabled(false);
}
}
}
_processOctreeStatsCounter++;
return statsMessageLength;
}

View file

@ -515,6 +515,8 @@ private:
std::map<void*, std::function<void()>> _preRenderLambdas;
std::mutex _preRenderLambdasLock;
std::atomic<uint32_t> _processOctreeStatsCounter { 0 };
};
#endif // hifi_Application_h