在调用 Delete 函数后调用 vtkObject 的成员函数是否安全?
It is safe to call a member function on a vtkObject after I call Delete function?
以下代码来自vtkAbstractTransform。我的应用程序在这个函数中崩溃了,这段代码安全吗?
void vtkTransformConcatenation::Concatenate(const double elements[16])
{
// concatenate the matrix with either the Pre- or PostMatrix
if (this->PreMultiplyFlag)
{
if (this->PreMatrix == NULL)
{
// add the matrix to the concatenation
vtkSimpleTransform *mtrans = vtkSimpleTransform::New();
this->Concatenate(mtrans);
mtrans->Delete(); // call Delete on mtrans
this->PreMatrixTransform = mtrans;
this->PreMatrix = mtrans->GetMatrix();
}
vtkMatrix4x4::Multiply4x4(*this->PreMatrix->Element, elements,
*this->PreMatrix->Element); // My application crushed here.
...
} }
没有。调用 Delete
可能会删除该对象。访问已删除的对象会调用未定义的行为。
从概念上讲,调用已删除对象的函数没有意义。删除对象后这个赋值
this->PreMatrixTransform = mtrans;
通常在 this->PreMatrixTransform 中放入垃圾值(可能是 NULL 值)。当这个变量被使用时(我很确定)它会导致崩溃。
以下代码来自vtkAbstractTransform。我的应用程序在这个函数中崩溃了,这段代码安全吗?
void vtkTransformConcatenation::Concatenate(const double elements[16])
{
// concatenate the matrix with either the Pre- or PostMatrix
if (this->PreMultiplyFlag)
{
if (this->PreMatrix == NULL)
{
// add the matrix to the concatenation
vtkSimpleTransform *mtrans = vtkSimpleTransform::New();
this->Concatenate(mtrans);
mtrans->Delete(); // call Delete on mtrans
this->PreMatrixTransform = mtrans;
this->PreMatrix = mtrans->GetMatrix();
}
vtkMatrix4x4::Multiply4x4(*this->PreMatrix->Element, elements,
*this->PreMatrix->Element); // My application crushed here.
...
} }
没有。调用 Delete
可能会删除该对象。访问已删除的对象会调用未定义的行为。
从概念上讲,调用已删除对象的函数没有意义。删除对象后这个赋值
this->PreMatrixTransform = mtrans;
通常在 this->PreMatrixTransform 中放入垃圾值(可能是 NULL 值)。当这个变量被使用时(我很确定)它会导致崩溃。