mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
Merge pull request #4080 from AndrewMeadows/bispinor
fixes for EntityServer crashes
This commit is contained in:
commit
33bb241f8a
7 changed files with 62 additions and 45 deletions
|
@ -404,6 +404,13 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
|
||||||
|
|
||||||
bool lastNodeDidntFit = false; // assume each node fits
|
bool lastNodeDidntFit = false; // assume each node fits
|
||||||
if (!nodeData->elementBag.isEmpty()) {
|
if (!nodeData->elementBag.isEmpty()) {
|
||||||
|
|
||||||
|
quint64 lockWaitStart = usecTimestampNow();
|
||||||
|
_myServer->getOctree()->lockForRead();
|
||||||
|
quint64 lockWaitEnd = usecTimestampNow();
|
||||||
|
lockWaitElapsedUsec = (float)(lockWaitEnd - lockWaitStart);
|
||||||
|
quint64 encodeStart = usecTimestampNow();
|
||||||
|
|
||||||
OctreeElement* subTree = nodeData->elementBag.extract();
|
OctreeElement* subTree = nodeData->elementBag.extract();
|
||||||
|
|
||||||
/* TODO: Looking for a way to prevent locking and encoding a tree that is not
|
/* TODO: Looking for a way to prevent locking and encoding a tree that is not
|
||||||
|
@ -447,12 +454,6 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
|
||||||
// it seems like it may be a good idea to include the lock time as part of the encode time
|
// it seems like it may be a good idea to include the lock time as part of the encode time
|
||||||
// are reported to client. Since you can encode without the lock
|
// are reported to client. Since you can encode without the lock
|
||||||
nodeData->stats.encodeStarted();
|
nodeData->stats.encodeStarted();
|
||||||
|
|
||||||
quint64 lockWaitStart = usecTimestampNow();
|
|
||||||
_myServer->getOctree()->lockForRead();
|
|
||||||
quint64 lockWaitEnd = usecTimestampNow();
|
|
||||||
lockWaitElapsedUsec = (float)(lockWaitEnd - lockWaitStart);
|
|
||||||
quint64 encodeStart = usecTimestampNow();
|
|
||||||
|
|
||||||
bytesWritten = _myServer->getOctree()->encodeTreeBitstream(subTree, &_packetData, nodeData->elementBag, params);
|
bytesWritten = _myServer->getOctree()->encodeTreeBitstream(subTree, &_packetData, nodeData->elementBag, params);
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,9 @@ void EntityTreeRenderer::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue EntityTreeRenderer::loadEntityScript(const EntityItemID& entityItemID) {
|
QScriptValue EntityTreeRenderer::loadEntityScript(const EntityItemID& entityItemID) {
|
||||||
|
_tree->lockForRead();
|
||||||
EntityItem* entity = static_cast<EntityTree*>(_tree)->findEntityByEntityItemID(entityItemID);
|
EntityItem* entity = static_cast<EntityTree*>(_tree)->findEntityByEntityItemID(entityItemID);
|
||||||
|
_tree->unlock();
|
||||||
return loadEntityScript(entity);
|
return loadEntityScript(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) {
|
||||||
_physicsInfo = NULL;
|
_physicsInfo = NULL;
|
||||||
_dirtyFlags = 0;
|
_dirtyFlags = 0;
|
||||||
_changedOnServer = 0;
|
_changedOnServer = 0;
|
||||||
|
_element = NULL;
|
||||||
initFromEntityItemID(entityItemID);
|
initFromEntityItemID(entityItemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +111,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
|
||||||
_physicsInfo = NULL;
|
_physicsInfo = NULL;
|
||||||
_dirtyFlags = 0;
|
_dirtyFlags = 0;
|
||||||
_changedOnServer = 0;
|
_changedOnServer = 0;
|
||||||
|
_element = NULL;
|
||||||
initFromEntityItemID(entityItemID);
|
initFromEntityItemID(entityItemID);
|
||||||
setProperties(properties);
|
setProperties(properties);
|
||||||
}
|
}
|
||||||
|
@ -117,6 +119,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
|
||||||
EntityItem::~EntityItem() {
|
EntityItem::~EntityItem() {
|
||||||
// be sure to clean up _physicsInfo before calling this dtor
|
// be sure to clean up _physicsInfo before calling this dtor
|
||||||
assert(_physicsInfo == NULL);
|
assert(_physicsInfo == NULL);
|
||||||
|
assert(_element == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
|
EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
|
||||||
|
|
|
@ -39,6 +39,7 @@ class EntityTreeElementExtraEncodeData;
|
||||||
/// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate
|
/// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate
|
||||||
/// one directly, instead you must only construct one of it's derived classes with additional features.
|
/// one directly, instead you must only construct one of it's derived classes with additional features.
|
||||||
class EntityItem {
|
class EntityItem {
|
||||||
|
friend class EntityTreeElement;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum EntityDirtyFlags {
|
enum EntityDirtyFlags {
|
||||||
|
@ -301,6 +302,7 @@ public:
|
||||||
void* getPhysicsInfo() const { return _physicsInfo; }
|
void* getPhysicsInfo() const { return _physicsInfo; }
|
||||||
void setPhysicsInfo(void* data) { _physicsInfo = data; }
|
void setPhysicsInfo(void* data) { _physicsInfo = data; }
|
||||||
|
|
||||||
|
EntityTreeElement* getElement() const { return _element; }
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init
|
virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init
|
||||||
|
@ -362,6 +364,8 @@ protected:
|
||||||
|
|
||||||
// DirtyFlags are set whenever a property changes that the EntitySimulation needs to know about.
|
// DirtyFlags are set whenever a property changes that the EntitySimulation needs to know about.
|
||||||
uint32_t _dirtyFlags; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation
|
uint32_t _dirtyFlags; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation
|
||||||
|
|
||||||
|
EntityTreeElement* _element; // back pointer to containing Element
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -682,6 +682,7 @@ void EntityTreeElement::cleanupEntities() {
|
||||||
uint16_t numberOfEntities = _entityItems->size();
|
uint16_t numberOfEntities = _entityItems->size();
|
||||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||||
EntityItem* entity = (*_entityItems)[i];
|
EntityItem* entity = (*_entityItems)[i];
|
||||||
|
entity->_element = NULL;
|
||||||
delete entity;
|
delete entity;
|
||||||
}
|
}
|
||||||
_entityItems->clear();
|
_entityItems->clear();
|
||||||
|
@ -693,6 +694,7 @@ bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) {
|
||||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||||
if ((*_entityItems)[i]->getEntityItemID() == id) {
|
if ((*_entityItems)[i]->getEntityItemID() == id) {
|
||||||
foundEntity = true;
|
foundEntity = true;
|
||||||
|
(*_entityItems)[i]->_element = NULL;
|
||||||
_entityItems->removeAt(i);
|
_entityItems->removeAt(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -701,7 +703,13 @@ bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityTreeElement::removeEntityItem(EntityItem* entity) {
|
bool EntityTreeElement::removeEntityItem(EntityItem* entity) {
|
||||||
return _entityItems->removeAll(entity) > 0;
|
int numEntries = _entityItems->removeAll(entity);
|
||||||
|
if (numEntries > 0) {
|
||||||
|
assert(entity->_element == this);
|
||||||
|
entity->_element = NULL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -808,7 +816,10 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTreeElement::addEntityItem(EntityItem* entity) {
|
void EntityTreeElement::addEntityItem(EntityItem* entity) {
|
||||||
|
assert(entity);
|
||||||
|
assert(entity->_element == NULL);
|
||||||
_entityItems->push_back(entity);
|
_entityItems->push_back(entity);
|
||||||
|
entity->_element = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// will average a "common reduced LOD view" from the the child elements...
|
// will average a "common reduced LOD view" from the the child elements...
|
||||||
|
|
|
@ -179,7 +179,7 @@ bool MovingEntitiesOperator::preRecursion(OctreeElement* element) {
|
||||||
|
|
||||||
// If this is one of the old elements we're looking for, then ask it to remove the old entity
|
// If this is one of the old elements we're looking for, then ask it to remove the old entity
|
||||||
if (!details.oldFound && entityTreeElement == details.oldContainingElement) {
|
if (!details.oldFound && entityTreeElement == details.oldContainingElement) {
|
||||||
entityTreeElement->removeEntityItem(details.entity);
|
// DO NOT remove the entity here. It will be removed when added to the destination element.
|
||||||
_foundOldCount++;
|
_foundOldCount++;
|
||||||
//details.oldFound = true; // TODO: would be nice to add this optimization
|
//details.oldFound = true; // TODO: would be nice to add this optimization
|
||||||
if (_wantDebug) {
|
if (_wantDebug) {
|
||||||
|
@ -193,8 +193,15 @@ bool MovingEntitiesOperator::preRecursion(OctreeElement* element) {
|
||||||
// If this element is the best fit for the new bounds of this entity then add the entity to the element
|
// If this element is the best fit for the new bounds of this entity then add the entity to the element
|
||||||
if (!details.newFound && entityTreeElement->bestFitBounds(details.newCube)) {
|
if (!details.newFound && entityTreeElement->bestFitBounds(details.newCube)) {
|
||||||
EntityItemID entityItemID = details.entity->getEntityItemID();
|
EntityItemID entityItemID = details.entity->getEntityItemID();
|
||||||
entityTreeElement->addEntityItem(details.entity);
|
// remove from the old before adding
|
||||||
_tree->setContainingElement(entityItemID, entityTreeElement);
|
EntityTreeElement* oldElement = details.entity->getElement();
|
||||||
|
if (oldElement != entityTreeElement) {
|
||||||
|
if (oldElement) {
|
||||||
|
oldElement->removeEntityItem(details.entity);
|
||||||
|
}
|
||||||
|
entityTreeElement->addEntityItem(details.entity);
|
||||||
|
_tree->setContainingElement(entityItemID, entityTreeElement);
|
||||||
|
}
|
||||||
_foundNewCount++;
|
_foundNewCount++;
|
||||||
//details.newFound = true; // TODO: would be nice to add this optimization
|
//details.newFound = true; // TODO: would be nice to add this optimization
|
||||||
if (_wantDebug) {
|
if (_wantDebug) {
|
||||||
|
@ -227,7 +234,7 @@ bool MovingEntitiesOperator::postRecursion(OctreeElement* element) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// It's not OK to prune if we have the potential of deleting the original containig element.
|
// It's not OK to prune if we have the potential of deleting the original containing element
|
||||||
// because if we prune the containing element then new might end up reallocating the same memory later
|
// because if we prune the containing element then new might end up reallocating the same memory later
|
||||||
// and that will confuse our logic.
|
// and that will confuse our logic.
|
||||||
//
|
//
|
||||||
|
|
|
@ -231,18 +231,19 @@ bool UpdateEntityOperator::preRecursion(OctreeElement* element) {
|
||||||
qDebug() << " *** REMOVING from ELEMENT ***";
|
qDebug() << " *** REMOVING from ELEMENT ***";
|
||||||
}
|
}
|
||||||
|
|
||||||
entityTreeElement->removeEntityItem(_existingEntity); // NOTE: only removes the entity, doesn't delete it
|
// the entity knows what element it's in, so we remove it from that one
|
||||||
|
// NOTE: we know we haven't yet added it to its new element because _removeOld is true
|
||||||
|
EntityTreeElement* oldElement = _existingEntity->getElement();
|
||||||
|
oldElement->removeEntityItem(_existingEntity);
|
||||||
|
_tree->setContainingElement(_entityItemID, NULL);
|
||||||
|
|
||||||
// If we haven't yet found the new location, then we need to
|
if (oldElement != _containingElement) {
|
||||||
// make sure to remove our entity to element map, because for
|
qDebug() << "WARNING entity moved during UpdateEntityOperator recursion";
|
||||||
// now we're not in that map
|
assert(! _containingElement->removeEntityItem(_existingEntity));
|
||||||
if (!_foundNew) {
|
}
|
||||||
_tree->setContainingElement(_entityItemID, NULL);
|
|
||||||
|
|
||||||
if (_wantDebug) {
|
|
||||||
qDebug() << " *** REMOVING from MAP ***";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (_wantDebug) {
|
||||||
|
qDebug() << " *** REMOVING from MAP ***";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_foundOld = true;
|
_foundOld = true;
|
||||||
|
@ -263,7 +264,6 @@ bool UpdateEntityOperator::preRecursion(OctreeElement* element) {
|
||||||
qDebug() << " entityTreeElement->bestFitBounds(_newEntityBox)=" << entityTreeElement->bestFitBounds(_newEntityBox);
|
qDebug() << " entityTreeElement->bestFitBounds(_newEntityBox)=" << entityTreeElement->bestFitBounds(_newEntityBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If this element is the best fit for the new entity properties, then add/or update it
|
// If this element is the best fit for the new entity properties, then add/or update it
|
||||||
if (entityTreeElement->bestFitBounds(_newEntityBox)) {
|
if (entityTreeElement->bestFitBounds(_newEntityBox)) {
|
||||||
|
|
||||||
|
@ -271,33 +271,14 @@ bool UpdateEntityOperator::preRecursion(OctreeElement* element) {
|
||||||
qDebug() << " *** THIS ELEMENT IS BEST FIT ***";
|
qDebug() << " *** THIS ELEMENT IS BEST FIT ***";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityTreeElement* oldElement = _existingEntity->getElement();
|
||||||
// if we are the existing containing element, then we can just do the update of the entity properties
|
// if we are the existing containing element, then we can just do the update of the entity properties
|
||||||
if (entityTreeElement == _containingElement) {
|
if (entityTreeElement == oldElement) {
|
||||||
|
|
||||||
if (_wantDebug) {
|
if (_wantDebug) {
|
||||||
qDebug() << " *** This is the same OLD ELEMENT ***";
|
qDebug() << " *** This is the same OLD ELEMENT ***";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We shouldn't be in a remove old case and also be the new best fit. This indicates that
|
|
||||||
// we have some kind of a logic error in this operator. But, it can handle it properly by setting
|
|
||||||
// the new properties for the entity and moving on. Still going to output a warning that if we
|
|
||||||
// see consistently we will want to address this.
|
|
||||||
if (_removeOld) {
|
|
||||||
qDebug() << "UNEXPECTED - UpdateEntityOperator - "
|
|
||||||
"we thought we needed to removeOld, but the old entity is our best fit.";
|
|
||||||
_removeOld = false;
|
|
||||||
|
|
||||||
// if we thought we were supposed to remove the old item, and we already did, then we need
|
|
||||||
// to repair this case.
|
|
||||||
if (_foundOld) {
|
|
||||||
if (_wantDebug) {
|
|
||||||
qDebug() << " *** REPAIRING PREVIOUS REMOVAL from ELEMENT and MAP ***";
|
|
||||||
}
|
|
||||||
entityTreeElement->addEntityItem(_existingEntity);
|
|
||||||
_tree->setContainingElement(_entityItemID, entityTreeElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the entity properties and mark our element as changed.
|
// set the entity properties and mark our element as changed.
|
||||||
_existingEntity->setProperties(_properties);
|
_existingEntity->setProperties(_properties);
|
||||||
if (_wantDebug) {
|
if (_wantDebug) {
|
||||||
|
@ -305,14 +286,22 @@ bool UpdateEntityOperator::preRecursion(OctreeElement* element) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// otherwise, this is an add case.
|
// otherwise, this is an add case.
|
||||||
|
if (oldElement) {
|
||||||
|
oldElement->removeEntityItem(_existingEntity);
|
||||||
|
if (oldElement != _containingElement) {
|
||||||
|
qDebug() << "WARNING entity moved during UpdateEntityOperator recursion";
|
||||||
|
}
|
||||||
|
}
|
||||||
entityTreeElement->addEntityItem(_existingEntity);
|
entityTreeElement->addEntityItem(_existingEntity);
|
||||||
_existingEntity->setProperties(_properties); // still need to update the properties!
|
|
||||||
_tree->setContainingElement(_entityItemID, entityTreeElement);
|
_tree->setContainingElement(_entityItemID, entityTreeElement);
|
||||||
|
|
||||||
|
_existingEntity->setProperties(_properties); // still need to update the properties!
|
||||||
if (_wantDebug) {
|
if (_wantDebug) {
|
||||||
qDebug() << " *** ADDING ENTITY to ELEMENT and MAP and SETTING PROPERTIES ***";
|
qDebug() << " *** ADDING ENTITY to ELEMENT and MAP and SETTING PROPERTIES ***";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_foundNew = true; // we found the new item!
|
_foundNew = true; // we found the new element
|
||||||
|
_removeOld = false; // and it has already been removed from the old
|
||||||
} else {
|
} else {
|
||||||
keepSearching = true;
|
keepSearching = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue