MAINT-4077: Refactoring to add copy constructors to the LLVisualParam class and all of its derived descendants in order to clarify ownership of memory pointers.

master
Stinson Linden 2014-05-23 21:56:44 +01:00
parent a13d2f7f70
commit 0160c514c5
14 changed files with 198 additions and 62 deletions

View File

@ -152,19 +152,31 @@ void LLDriverParamInfo::toStream(std::ostream &out)
// LLDriverParam
//-----------------------------------------------------------------------------
LLDriverParam::LLDriverParam(LLAvatarAppearance *appearance, LLWearable* wearable /* = NULL */) :
LLDriverParam::LLDriverParam(LLAvatarAppearance *appearance, LLWearable* wearable /* = NULL */)
: LLViewerVisualParam(),
mDefaultVec(),
mDriven(),
mCurrentDistortionParam( NULL ),
mAvatarAppearance(appearance),
mWearablep(wearable)
{
llassert(mAvatarAppearance);
if (mWearablep)
{
llassert(mAvatarAppearance->isSelf());
}
llassert((mWearablep == NULL) || mAvatarAppearance->isSelf());
mDefaultVec.clear();
}
LLDriverParam::LLDriverParam(const LLDriverParam& pOther)
: LLViewerVisualParam(pOther),
mDefaultVec(pOther.mDefaultVec),
mDriven(pOther.mDriven),
mCurrentDistortionParam(pOther.mCurrentDistortionParam),
mAvatarAppearance(pOther.mAvatarAppearance),
mWearablep(pOther.mWearablep)
{
llassert(mAvatarAppearance);
llassert((mWearablep == NULL) || mAvatarAppearance->isSelf());
}
LLDriverParam::~LLDriverParam()
{
}
@ -186,13 +198,7 @@ BOOL LLDriverParam::setInfo(LLDriverParamInfo *info)
/*virtual*/ LLViewerVisualParam* LLDriverParam::cloneParam(LLWearable* wearable) const
{
llassert(wearable);
LLDriverParam *new_param = new LLDriverParam(mAvatarAppearance, wearable);
// FIXME DRANO this clobbers mWearablep, which means any code
// currently using mWearablep is wrong, or at least untested.
*new_param = *this;
//new_param->mWearablep = wearable;
// new_param->mDriven.clear(); // clear driven list to avoid overwriting avatar driven params from wearables.
return new_param;
return new LLDriverParam(*this);
}
void LLDriverParam::setWeight(F32 weight, BOOL upload_bake)

View File

@ -129,6 +129,7 @@ public:
const LLViewerVisualParam* getDrivenParam(S32 index) const;
protected:
LLDriverParam(const LLDriverParam& pOther);
F32 getDrivenWeight(const LLDrivenEntry* driven, F32 input_weight);
void setDrivenWeight(LLDrivenEntry *driven, F32 driven_weight, bool upload_bake);

View File

@ -315,10 +315,27 @@ BOOL LLPolyMorphTargetInfo::parseXml(LLXmlTreeNode* node)
// LLPolyMorphTarget()
//-----------------------------------------------------------------------------
LLPolyMorphTarget::LLPolyMorphTarget(LLPolyMesh *poly_mesh)
: mMorphData(NULL), mMesh(poly_mesh),
mVertMask(NULL),
mLastSex(SEX_FEMALE),
mNumMorphMasksPending(0)
: LLViewerVisualParam(),
mMorphData(NULL),
mMesh(poly_mesh),
mVertMask(NULL),
mLastSex(SEX_FEMALE),
mNumMorphMasksPending(0),
mVolumeMorphs()
{
}
//-----------------------------------------------------------------------------
// LLPolyMorphTarget()
//-----------------------------------------------------------------------------
LLPolyMorphTarget::LLPolyMorphTarget(const LLPolyMorphTarget& pOther)
: LLViewerVisualParam(pOther),
mMorphData(pOther.mMorphData),
mMesh(pOther.mMesh),
mVertMask(pOther.mVertMask == NULL ? NULL : new LLPolyVertexMask(*pOther.mVertMask)),
mLastSex(pOther.mLastSex),
mNumMorphMasksPending(pOther.mNumMorphMasksPending),
mVolumeMorphs(pOther.mVolumeMorphs)
{
}
@ -327,10 +344,8 @@ LLPolyMorphTarget::LLPolyMorphTarget(LLPolyMesh *poly_mesh)
//-----------------------------------------------------------------------------
LLPolyMorphTarget::~LLPolyMorphTarget()
{
if (mVertMask)
{
delete mVertMask;
}
delete mVertMask;
mVertMask = NULL;
}
//-----------------------------------------------------------------------------
@ -385,9 +400,7 @@ BOOL LLPolyMorphTarget::setInfo(LLPolyMorphTargetInfo* info)
/*virtual*/ LLViewerVisualParam* LLPolyMorphTarget::cloneParam(LLWearable* wearable) const
{
LLPolyMorphTarget *new_param = new LLPolyMorphTarget(mMesh);
*new_param = *this;
return new_param;
return new LLPolyMorphTarget(*this);
}
#if 0 // obsolete
@ -722,10 +735,25 @@ void LLPolyMorphTarget::applyMask(U8 *maskTextureData, S32 width, S32 height, S3
// LLPolyVertexMask()
//-----------------------------------------------------------------------------
LLPolyVertexMask::LLPolyVertexMask(LLPolyMorphData* morph_data)
: mWeights(new F32[morph_data->mNumIndices]),
mMorphData(morph_data),
mWeightsGenerated(FALSE)
{
mWeights = new F32[morph_data->mNumIndices];
mMorphData = morph_data;
mWeightsGenerated = FALSE;
llassert(mMorphData != NULL);
llassert(mMorphData->mNumIndices > 0);
}
//-----------------------------------------------------------------------------
// LLPolyVertexMask()
//-----------------------------------------------------------------------------
LLPolyVertexMask::LLPolyVertexMask(const LLPolyVertexMask& pOther)
: mWeights(new F32[pOther.mMorphData->mNumIndices]),
mMorphData(pOther.mMorphData),
mWeightsGenerated(pOther.mWeightsGenerated)
{
llassert(mMorphData != NULL);
llassert(mMorphData->mNumIndices > 0);
memcpy(mWeights, pOther.mWeights, sizeof(F32) * mMorphData->mNumIndices);
}
//-----------------------------------------------------------------------------
@ -733,7 +761,8 @@ LLPolyVertexMask::LLPolyVertexMask(LLPolyMorphData* morph_data)
//-----------------------------------------------------------------------------
LLPolyVertexMask::~LLPolyVertexMask()
{
delete[] mWeights;
delete [] mWeights;
mWeights = NULL;
}
//-----------------------------------------------------------------------------

View File

@ -91,6 +91,7 @@ class LLPolyVertexMask
{
public:
LLPolyVertexMask(LLPolyMorphData* morph_data);
LLPolyVertexMask(const LLPolyVertexMask& pOther);
~LLPolyVertexMask();
void generateMask(U8 *maskData, S32 width, S32 height, S32 num_components, BOOL invert, LLVector4a *clothing_weights);
@ -182,6 +183,8 @@ public:
void addPendingMorphMask() { mNumMorphMasksPending++; }
protected:
LLPolyMorphTarget(const LLPolyMorphTarget& pOther);
LLPolyMorphData* mMorphData;
LLPolyMesh* mMesh;
LLPolyVertexMask * mVertMask;

View File

@ -104,9 +104,25 @@ BOOL LLPolySkeletalDistortionInfo::parseXml(LLXmlTreeNode* node)
// LLPolySkeletalDistortion()
//-----------------------------------------------------------------------------
LLPolySkeletalDistortion::LLPolySkeletalDistortion(LLAvatarAppearance *avatarp)
: LLViewerVisualParam(),
mDefaultVec(),
mJointScales(),
mJointOffsets(),
mAvatar(avatarp)
{
mDefaultVec.splat(0.001f);
}
//-----------------------------------------------------------------------------
// LLPolySkeletalDistortion()
//-----------------------------------------------------------------------------
LLPolySkeletalDistortion::LLPolySkeletalDistortion(const LLPolySkeletalDistortion &pOther)
: LLViewerVisualParam(pOther),
mDefaultVec(pOther.mDefaultVec),
mJointScales(pOther.mJointScales),
mJointOffsets(pOther.mJointOffsets),
mAvatar(pOther.mAvatar)
{
mAvatar = avatarp;
mDefaultVec.splat(0.001f);
}
//-----------------------------------------------------------------------------
@ -171,9 +187,7 @@ BOOL LLPolySkeletalDistortion::setInfo(LLPolySkeletalDistortionInfo *info)
/*virtual*/ LLViewerVisualParam* LLPolySkeletalDistortion::cloneParam(LLWearable* wearable) const
{
LLPolySkeletalDistortion *new_param = new LLPolySkeletalDistortion(mAvatar);
*new_param = *this;
return new_param;
return new LLPolySkeletalDistortion(*this);
}
//-----------------------------------------------------------------------------

View File

@ -118,6 +118,8 @@ public:
/*virtual*/ const LLVector4a* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return NULL;};
protected:
LLPolySkeletalDistortion(const LLPolySkeletalDistortion& pOther);
LL_ALIGN_16(LLVector4a mDefaultVec);
typedef std::map<LLJoint*, LLVector3> joint_vec_map_t;
joint_vec_map_t mJointScales;

View File

@ -90,17 +90,31 @@ const std::string& LLTexGlobalColor::getName() const
//-----------------------------------------------------------------------------
// LLTexParamGlobalColor
//-----------------------------------------------------------------------------
LLTexParamGlobalColor::LLTexParamGlobalColor(LLTexGlobalColor* tex_global_color) :
LLTexLayerParamColor(tex_global_color->getAvatarAppearance()),
LLTexParamGlobalColor::LLTexParamGlobalColor(LLTexGlobalColor* tex_global_color)
: LLTexLayerParamColor(tex_global_color->getAvatarAppearance()),
mTexGlobalColor(tex_global_color)
{
}
//-----------------------------------------------------------------------------
// LLTexParamGlobalColor
//-----------------------------------------------------------------------------
LLTexParamGlobalColor::LLTexParamGlobalColor(const LLTexParamGlobalColor& pOther)
: LLTexLayerParamColor(pOther),
mTexGlobalColor(pOther.mTexGlobalColor)
{
}
//-----------------------------------------------------------------------------
// ~LLTexParamGlobalColor
//-----------------------------------------------------------------------------
LLTexParamGlobalColor::~LLTexParamGlobalColor()
{
}
/*virtual*/ LLViewerVisualParam* LLTexParamGlobalColor::cloneParam(LLWearable* wearable) const
{
LLTexParamGlobalColor *new_param = new LLTexParamGlobalColor(mTexGlobalColor);
*new_param = *this;
return new_param;
return new LLTexParamGlobalColor(*this);
}
void LLTexParamGlobalColor::onGlobalColorChanged(bool upload_bake)

View File

@ -73,8 +73,10 @@ class LLTexParamGlobalColor : public LLTexLayerParamColor
{
public:
LLTexParamGlobalColor(LLTexGlobalColor *tex_color);
virtual ~LLTexParamGlobalColor();
/*virtual*/ LLViewerVisualParam* cloneParam(LLWearable* wearable) const;
protected:
LLTexParamGlobalColor(const LLTexParamGlobalColor& pOther);
/*virtual*/ void onGlobalColorChanged(bool upload_bake);
private:
LLTexGlobalColor* mTexGlobalColor;

View File

@ -40,7 +40,8 @@
//-----------------------------------------------------------------------------
// LLTexLayerParam
//-----------------------------------------------------------------------------
LLTexLayerParam::LLTexLayerParam(LLTexLayerInterface *layer) :
LLTexLayerParam::LLTexLayerParam(LLTexLayerInterface *layer)
: LLViewerVisualParam(),
mTexLayer(layer),
mAvatarAppearance(NULL)
{
@ -54,12 +55,19 @@ LLTexLayerParam::LLTexLayerParam(LLTexLayerInterface *layer) :
}
}
LLTexLayerParam::LLTexLayerParam(LLAvatarAppearance *appearance) :
LLTexLayerParam::LLTexLayerParam(LLAvatarAppearance *appearance)
: LLViewerVisualParam(),
mTexLayer(NULL),
mAvatarAppearance(appearance)
{
}
LLTexLayerParam::LLTexLayerParam(const LLTexLayerParam& pOther)
: LLViewerVisualParam(pOther),
mTexLayer(pOther.mTexLayer),
mAvatarAppearance(pOther.mAvatarAppearance)
{
}
BOOL LLTexLayerParam::setInfo(LLViewerVisualParamInfo *info, BOOL add_to_appearance)
{
@ -112,9 +120,11 @@ void LLTexLayerParamAlpha::getCacheByteCount(S32* gl_bytes)
}
}
LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLTexLayerInterface* layer) :
LLTexLayerParam(layer),
LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLTexLayerInterface* layer)
: LLTexLayerParam(layer),
mCachedProcessedTexture(NULL),
mStaticImageTGA(),
mStaticImageRaw(),
mNeedsCreateTexture(FALSE),
mStaticImageInvalid(FALSE),
mAvgDistortionVec(1.f, 1.f, 1.f),
@ -123,9 +133,11 @@ LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLTexLayerInterface* layer) :
sInstances.push_front(this);
}
LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLAvatarAppearance* appearance) :
LLTexLayerParam(appearance),
LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLAvatarAppearance* appearance)
: LLTexLayerParam(appearance),
mCachedProcessedTexture(NULL),
mStaticImageTGA(),
mStaticImageRaw(),
mNeedsCreateTexture(FALSE),
mStaticImageInvalid(FALSE),
mAvgDistortionVec(1.f, 1.f, 1.f),
@ -134,6 +146,18 @@ LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLAvatarAppearance* appearance) :
sInstances.push_front(this);
}
LLTexLayerParamAlpha::LLTexLayerParamAlpha(const LLTexLayerParamAlpha& pOther)
: LLTexLayerParam(pOther),
mCachedProcessedTexture(pOther.mCachedProcessedTexture),
mStaticImageTGA(pOther.mStaticImageTGA),
mStaticImageRaw(pOther.mStaticImageRaw),
mNeedsCreateTexture(pOther.mNeedsCreateTexture),
mStaticImageInvalid(pOther.mStaticImageInvalid),
mAvgDistortionVec(pOther.mAvgDistortionVec),
mCachedEffectiveWeight(pOther.mCachedEffectiveWeight)
{
sInstances.push_front(this);
}
LLTexLayerParamAlpha::~LLTexLayerParamAlpha()
{
@ -143,9 +167,7 @@ LLTexLayerParamAlpha::~LLTexLayerParamAlpha()
/*virtual*/ LLViewerVisualParam* LLTexLayerParamAlpha::cloneParam(LLWearable* wearable) const
{
LLTexLayerParamAlpha *new_param = new LLTexLayerParamAlpha(mTexLayer);
*new_param = *this;
return new_param;
return new LLTexLayerParamAlpha(*this);
}
void LLTexLayerParamAlpha::deleteCaches()
@ -399,27 +421,31 @@ BOOL LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node)
LLTexLayerParamColor::LLTexLayerParamColor(LLTexLayerInterface* layer) :
LLTexLayerParam(layer),
LLTexLayerParamColor::LLTexLayerParamColor(LLTexLayerInterface* layer)
: LLTexLayerParam(layer),
mAvgDistortionVec(1.f, 1.f, 1.f)
{
}
LLTexLayerParamColor::LLTexLayerParamColor(LLAvatarAppearance *appearance) :
LLTexLayerParam(appearance),
LLTexLayerParamColor::LLTexLayerParamColor(LLAvatarAppearance *appearance)
: LLTexLayerParam(appearance),
mAvgDistortionVec(1.f, 1.f, 1.f)
{
}
LLTexLayerParamColor::LLTexLayerParamColor(const LLTexLayerParamColor& pOther)
: LLTexLayerParam(pOther),
mAvgDistortionVec(pOther.mAvgDistortionVec)
{
}
LLTexLayerParamColor::~LLTexLayerParamColor()
{
}
/*virtual*/ LLViewerVisualParam* LLTexLayerParamColor::cloneParam(LLWearable* wearable) const
{
LLTexLayerParamColor *new_param = new LLTexLayerParamColor(mTexLayer);
*new_param = *this;
return new_param;
return new LLTexLayerParamColor(*this);
}
LLColor4 LLTexLayerParamColor::getNetColor() const

View File

@ -52,6 +52,8 @@ public:
/*virtual*/ LLViewerVisualParam* cloneParam(LLWearable* wearable) const = 0;
protected:
LLTexLayerParam(const LLTexLayerParam& pOther);
LLTexLayerInterface* mTexLayer;
LLAvatarAppearance* mAvatarAppearance;
};
@ -102,6 +104,8 @@ public:
BOOL getMultiplyBlend() const;
private:
LLTexLayerParamAlpha(const LLTexLayerParamAlpha& pOther);
LLPointer<LLGLTexture> mCachedProcessedTexture;
LLPointer<LLImageTGA> mStaticImageTGA;
LLPointer<LLImageRaw> mStaticImageRaw;
@ -190,6 +194,8 @@ public:
// New functions
LLColor4 getNetColor() const;
protected:
LLTexLayerParamColor(const LLTexLayerParamColor& pOther);
virtual void onGlobalColorChanged(bool upload_bake) {}
private:
LL_ALIGN_16(LLVector4a mAvgDistortionVec);

View File

@ -123,6 +123,22 @@ BOOL LLViewerVisualParamInfo::parseXml(LLXmlTreeNode *node)
// LLViewerVisualParam()
//-----------------------------------------------------------------------------
LLViewerVisualParam::LLViewerVisualParam()
: LLVisualParam()
{
}
//-----------------------------------------------------------------------------
// LLViewerVisualParam()
//-----------------------------------------------------------------------------
LLViewerVisualParam::LLViewerVisualParam(const LLViewerVisualParam& pOther)
: LLVisualParam(pOther)
{
}
//-----------------------------------------------------------------------------
// ~LLViewerVisualParam()
//-----------------------------------------------------------------------------
LLViewerVisualParam::~LLViewerVisualParam()
{
}

View File

@ -70,7 +70,7 @@ class LLViewerVisualParam : public LLVisualParam
{
public:
LLViewerVisualParam();
/*virtual*/ ~LLViewerVisualParam(){};
virtual ~LLViewerVisualParam();
// Special: These functions are overridden by child classes
LLViewerVisualParamInfo *getInfo() const { return (LLViewerVisualParamInfo*)mInfo; };
@ -105,6 +105,8 @@ public:
BOOL getCrossWearable() const { return getInfo()->mCrossWearable; }
protected:
LLViewerVisualParam(const LLViewerVisualParam& pOther);
} LL_ALIGN_POSTFIX(16);
#endif // LL_LLViewerVisualParam_H

View File

@ -159,29 +159,42 @@ void LLVisualParamInfo::toStream(std::ostream &out)
//-----------------------------------------------------------------------------
// LLVisualParam()
//-----------------------------------------------------------------------------
LLVisualParam::LLVisualParam()
:
mCurWeight( 0.f ),
LLVisualParam::LLVisualParam()
: mCurWeight( 0.f ),
mLastWeight( 0.f ),
mNext( NULL ),
mTargetWeight( 0.f ),
mIsAnimating( FALSE ),
mIsDummy(FALSE),
mID( -1 ),
mInfo( 0 ),
mIsDummy(FALSE),
mParamLocation(LOC_UNKNOWN)
{
}
//-----------------------------------------------------------------------------
// LLVisualParam()
//-----------------------------------------------------------------------------
LLVisualParam::LLVisualParam(const LLVisualParam& pOther)
: mCurWeight(pOther.mCurWeight),
mLastWeight(pOther.mLastWeight),
mNext(pOther.mNext),
mTargetWeight(pOther.mTargetWeight),
mIsAnimating(pOther.mIsAnimating),
mIsDummy(pOther.mIsDummy),
mID(pOther.mID),
mInfo(pOther.mInfo),
mParamLocation(pOther.mParamLocation)
{
}
//-----------------------------------------------------------------------------
// ~LLVisualParam()
//-----------------------------------------------------------------------------
LLVisualParam::~LLVisualParam()
{
if (mNext != NULL)
{
delete mNext;
}
delete mNext;
mNext = NULL;
}
/*

View File

@ -166,6 +166,8 @@ public:
EParamLocation getParamLocation() const { return mParamLocation; }
protected:
LLVisualParam(const LLVisualParam& pOther);
F32 mCurWeight; // current weight
F32 mLastWeight; // last weight
LLVisualParam* mNext; // next param in a shared chain