diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 715c24b8ee..a5314bf4a8 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -55,6 +55,7 @@ typedef unsigned long long quint64; #include #include #include +#include #include "AABox.h" #include "HeadData.h" @@ -138,10 +139,6 @@ class AttachmentData; class Transform; using TransformPointer = std::shared_ptr; -// 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 diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index fe7fccaece..656a6bd281 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -12,6 +12,7 @@ #include "EntityItemID.h" #include +#include #include #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()); diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index f3e5625484..0470a032ce 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -23,6 +23,12 @@ #include #include +#include + + +// 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 diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 19fa9f81b3..f75557f73f 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -12,6 +12,7 @@ #include #include "DependencyManager.h" +#include "SharedUtil.h" #include "SpatiallyNestable.h" const float defaultAACubeSize = 1.0f; @@ -856,7 +857,11 @@ QList 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; } }