Handle edge cases of AVATAR_SELF_ID being used with entities

This commit is contained in:
Ryan Huffman 2016-09-13 16:24:22 -07:00
parent 23450e929b
commit 5e8c8f84b5
4 changed files with 22 additions and 5 deletions

View file

@ -55,6 +55,7 @@ typedef unsigned long long quint64;
#include <NumericalConstants.h>
#include <Packed.h>
#include <ThreadSafeValueCache.h>
#include <SharedUtil.h>
#include "AABox.h"
#include "HeadData.h"
@ -138,10 +139,6 @@ class AttachmentData;
class Transform;
using TransformPointer = std::shared_ptr<Transform>;
// When writing out avatarEntities to a QByteArray, if the parentID is the ID of MyAvatar, use this ID instead. This allows
// the value to be reset when the sessionID changes.
const QUuid AVATAR_SELF_ID = QUuid("{00000000-0000-0000-0000-000000000001}");
class AvatarData : public QObject, public SpatiallyNestable {
Q_OBJECT

View file

@ -12,6 +12,7 @@
#include "EntityItemID.h"
#include <VariantMapToScriptValue.h>
#include <SharedUtil.h>
#include <SpatialParentFinder.h>
#include "EntitiesLogging.h"
@ -181,6 +182,11 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
propertiesWithSimID.setOwningAvatarID(myNodeID);
}
if (propertiesWithSimID.getParentID() == AVATAR_SELF_ID) {
qDebug() << "ERROR: Cannot set entity parent ID to the local-only MyAvatar ID";
propertiesWithSimID.setParentID(QUuid());
}
auto dimensions = propertiesWithSimID.getDimensions();
float volume = dimensions.x * dimensions.y * dimensions.z;
auto density = propertiesWithSimID.getDensity();
@ -357,6 +363,9 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
if (!scriptSideProperties.parentIDChanged()) {
properties.setParentID(entity->getParentID());
} else if (scriptSideProperties.getParentID() == AVATAR_SELF_ID) {
qDebug() << "ERROR: Cannot set entity parent ID to the local-only MyAvatar ID";
properties.setParentID(QUuid());
}
if (!scriptSideProperties.parentJointIndexChanged()) {
properties.setParentJointIndex(entity->getParentJointIndex());

View file

@ -23,6 +23,12 @@
#include <QtCore/QDebug>
#include <QtCore/QCoreApplication>
#include <QUuid>
// When writing out avatarEntities to a QByteArray, if the parentID is the ID of MyAvatar, use this ID instead. This allows
// the value to be reset when the sessionID changes.
const QUuid AVATAR_SELF_ID = QUuid("{00000000-0000-0000-0000-000000000001}");
// Access to the global instance pointer to enable setting / unsetting
template <typename T>

View file

@ -12,6 +12,7 @@
#include <QQueue>
#include "DependencyManager.h"
#include "SharedUtil.h"
#include "SpatiallyNestable.h"
const float defaultAACubeSize = 1.0f;
@ -856,7 +857,11 @@ QList<SpatiallyNestablePointer> SpatiallyNestable::getChildren() const {
_childrenLock.withReadLock([&] {
foreach(SpatiallyNestableWeakPointer childWP, _children.values()) {
SpatiallyNestablePointer child = childWP.lock();
if (child && child->_parentKnowsMe && (child->getParentID() == getID() || child->getParentID() == QUuid("{00000000-0000-0000-0000-000000000001}"))) {
// An object can set MyAvatar to be its parent using two IDs: the session ID and the special AVATAR_SELF_ID
// Because we only recognize an object as having one ID, we need to check for the second possible ID here.
// In practice, the AVATAR_SELF_ID should only be used for local-only objects.
if (child && child->_parentKnowsMe && (child->getParentID() == getID() ||
(getNestableType() == NestableType::Avatar && child->getParentID() == AVATAR_SELF_ID))) {
children << child;
}
}