mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 21:53:47 +02:00
Revert "Speculative fix for infinite loop in SafeLanding"
This reverts commit 52acfc9333
.
This commit is contained in:
parent
487515d956
commit
929e829801
2 changed files with 34 additions and 45 deletions
|
@ -39,7 +39,6 @@ bool SafeLanding::SequenceLessThan::operator()(const OCTREE_PACKET_SEQUENCE& a,
|
||||||
|
|
||||||
void SafeLanding::startTracking(QSharedPointer<EntityTreeRenderer> entityTreeRenderer) {
|
void SafeLanding::startTracking(QSharedPointer<EntityTreeRenderer> entityTreeRenderer) {
|
||||||
if (!entityTreeRenderer.isNull()) {
|
if (!entityTreeRenderer.isNull()) {
|
||||||
qCDebug(interfaceapp) << "SafeLanding has started tracking";
|
|
||||||
auto entityTree = entityTreeRenderer->getTree();
|
auto entityTree = entityTreeRenderer->getTree();
|
||||||
if (entityTree && !_trackingEntities) {
|
if (entityTree && !_trackingEntities) {
|
||||||
Locker lock(_lock);
|
Locker lock(_lock);
|
||||||
|
@ -105,55 +104,47 @@ void SafeLanding::updateTracking() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Locker lock(_lock);
|
{
|
||||||
|
Locker lock(_lock);
|
||||||
bool enableInterstitial = DependencyManager::get<NodeList>()->getDomainHandler().getInterstitialModeEnabled();
|
bool enableInterstitial = DependencyManager::get<NodeList>()->getDomainHandler().getInterstitialModeEnabled();
|
||||||
auto entityMapIter = _trackedEntities.begin();
|
auto entityMapIter = _trackedEntities.begin();
|
||||||
while (entityMapIter != _trackedEntities.end()) {
|
while (entityMapIter != _trackedEntities.end()) {
|
||||||
auto entity = entityMapIter->second;
|
auto entity = entityMapIter->second;
|
||||||
bool isVisuallyReady = true;
|
bool isVisuallyReady = true;
|
||||||
if (enableInterstitial) {
|
if (enableInterstitial) {
|
||||||
auto entityRenderable = _entityTreeRenderer->renderableForEntityId(entityMapIter->first);
|
auto entityRenderable = _entityTreeRenderer->renderableForEntityId(entityMapIter->first);
|
||||||
if (!entityRenderable) {
|
if (!entityRenderable) {
|
||||||
_entityTreeRenderer->addingEntity(entityMapIter->first);
|
_entityTreeRenderer->addingEntity(entityMapIter->first);
|
||||||
|
}
|
||||||
|
isVisuallyReady = entity->isVisuallyReady() || (!entityRenderable && !entity->isParentPathComplete());
|
||||||
|
}
|
||||||
|
if (isEntityPhysicsReady(entity) && isVisuallyReady) {
|
||||||
|
entityMapIter = _trackedEntities.erase(entityMapIter);
|
||||||
|
} else {
|
||||||
|
entityMapIter++;
|
||||||
}
|
}
|
||||||
isVisuallyReady = entity->isVisuallyReady() || (!entityRenderable && !entity->isParentPathComplete());
|
|
||||||
}
|
}
|
||||||
if (isEntityPhysicsReady(entity) && isVisuallyReady) {
|
if (enableInterstitial) {
|
||||||
entityMapIter = _trackedEntities.erase(entityMapIter);
|
_trackedEntityStabilityCount++;
|
||||||
} else {
|
|
||||||
entityMapIter++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enableInterstitial) {
|
|
||||||
_trackedEntityStabilityCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_trackedEntities.empty()) {
|
if (_trackedEntities.empty()) {
|
||||||
// no more tracked entities --> check sequenceNumbers
|
// no more tracked entities --> check sequenceNumbers
|
||||||
if (_sequenceStart != SafeLanding::INVALID_SEQUENCE) {
|
if (_sequenceStart != SafeLanding::INVALID_SEQUENCE) {
|
||||||
bool shouldStop = false;
|
bool shouldStop = false;
|
||||||
auto sequenceSize = _sequenceEnd - _sequenceStart; // this works even in rollover case
|
{
|
||||||
auto startIter = _sequenceNumbers.find(_sequenceStart);
|
Locker lock(_lock);
|
||||||
auto endIter = _sequenceNumbers.find(_sequenceEnd - 1);
|
auto sequenceSize = _sequenceEnd - _sequenceStart; // this works even in rollover case
|
||||||
|
auto startIter = _sequenceNumbers.find(_sequenceStart);
|
||||||
|
auto endIter = _sequenceNumbers.find(_sequenceEnd - 1);
|
||||||
|
|
||||||
bool missingSequenceNumbers = qApp->isMissingSequenceNumbers();
|
bool missingSequenceNumbers = qApp->isMissingSequenceNumbers();
|
||||||
|
shouldStop = (sequenceSize == 0 ||
|
||||||
// If the EntityQueryInitialResultsComplete packet is really late due to packet loss, the
|
|
||||||
// _sequenceNumbers map will be filled with unnecessary sequence numbers. This can cause
|
|
||||||
// the main thread to enter an infinite loop in the std::distance() calculation.
|
|
||||||
// Try to guard against this. This might cause physics to be enabled too soon, but
|
|
||||||
// that is preferable to locking up.
|
|
||||||
bool tooManySequenceNumbers = _sequenceNumbers.size() >= (std::numeric_limits<OCTREE_PACKET_SEQUENCE>::max() / 2);
|
|
||||||
|
|
||||||
qCDebug(interfaceapp) << "SafeLanding has no more tracked entities and" << _sequenceNumbers.size() << "sequence numbers";
|
|
||||||
|
|
||||||
shouldStop = (sequenceSize == 0 ||
|
|
||||||
(startIter != _sequenceNumbers.end() &&
|
(startIter != _sequenceNumbers.end() &&
|
||||||
endIter != _sequenceNumbers.end() &&
|
endIter != _sequenceNumbers.end() &&
|
||||||
!tooManySequenceNumbers &&
|
|
||||||
((distance(startIter, endIter) == sequenceSize - 1) || !missingSequenceNumbers)));
|
((distance(startIter, endIter) == sequenceSize - 1) || !missingSequenceNumbers)));
|
||||||
|
}
|
||||||
if (shouldStop) {
|
if (shouldStop) {
|
||||||
stopTracking();
|
stopTracking();
|
||||||
}
|
}
|
||||||
|
@ -162,8 +153,6 @@ void SafeLanding::updateTracking() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SafeLanding::stopTracking() {
|
void SafeLanding::stopTracking() {
|
||||||
qCDebug(interfaceapp) << "SafeLanding has stopped tracking";
|
|
||||||
|
|
||||||
Locker lock(_lock);
|
Locker lock(_lock);
|
||||||
if (_trackingEntities) {
|
if (_trackingEntities) {
|
||||||
_trackingEntities = false;
|
_trackingEntities = false;
|
||||||
|
@ -180,7 +169,6 @@ void SafeLanding::stopTracking() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SafeLanding::reset() {
|
void SafeLanding::reset() {
|
||||||
Locker lock(_lock);
|
|
||||||
_trackingEntities = false;
|
_trackingEntities = false;
|
||||||
_trackedEntities.clear();
|
_trackedEntities.clear();
|
||||||
_maxTrackedEntityCount = 0;
|
_maxTrackedEntityCount = 0;
|
||||||
|
@ -189,7 +177,6 @@ void SafeLanding::reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SafeLanding::trackingIsComplete() const {
|
bool SafeLanding::trackingIsComplete() const {
|
||||||
Locker lock(_lock);
|
|
||||||
return !_trackingEntities && (_sequenceStart != SafeLanding::INVALID_SEQUENCE);
|
return !_trackingEntities && (_sequenceStart != SafeLanding::INVALID_SEQUENCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,8 +241,10 @@ void SafeLanding::debugDumpSequenceIDs() const {
|
||||||
++itr;
|
++itr;
|
||||||
while (itr != _sequenceNumbers.end()) {
|
while (itr != _sequenceNumbers.end()) {
|
||||||
OCTREE_PACKET_SEQUENCE s = *itr;
|
OCTREE_PACKET_SEQUENCE s = *itr;
|
||||||
qCDebug(interfaceapp) << " " << (int32_t)s;
|
if (s != p + 1) {
|
||||||
p = s;
|
qCDebug(interfaceapp) << "Gap from" << (int32_t)p << "to" << (int32_t)s << "(exclusive)";
|
||||||
|
p = s;
|
||||||
|
}
|
||||||
++itr;
|
++itr;
|
||||||
}
|
}
|
||||||
if (p != SafeLanding::INVALID_SEQUENCE) {
|
if (p != SafeLanding::INVALID_SEQUENCE) {
|
||||||
|
|
|
@ -51,8 +51,8 @@ private:
|
||||||
bool isEntityPhysicsReady(const EntityItemPointer& entity);
|
bool isEntityPhysicsReady(const EntityItemPointer& entity);
|
||||||
void debugDumpSequenceIDs() const;
|
void debugDumpSequenceIDs() const;
|
||||||
|
|
||||||
mutable std::recursive_mutex _lock;
|
std::mutex _lock;
|
||||||
using Locker = std::lock_guard<std::recursive_mutex>;
|
using Locker = std::lock_guard<std::mutex>;
|
||||||
bool _trackingEntities { false };
|
bool _trackingEntities { false };
|
||||||
QSharedPointer<EntityTreeRenderer> _entityTreeRenderer;
|
QSharedPointer<EntityTreeRenderer> _entityTreeRenderer;
|
||||||
using EntityMap = std::map<EntityItemID, EntityItemPointer>;
|
using EntityMap = std::map<EntityItemID, EntityItemPointer>;
|
||||||
|
|
Loading…
Reference in a new issue