Hi. I have created my own entity. At the end of subMoveGripPointsAt (at the end meaning - moving is done) I have to call an external function. This function does some operations and indirectly opens my entity for read or write. But then I get an error saying that object is already opened for write. So to workaround this problem I am closing my entity just before call this external function. Everything works, but my question is - is it safe to close entity in that way?
Here is my code:
Acad::ErrorStatus ARXEntity::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset) { assertWriteEnabled(); //if moving then show preview if((indices.length() > 0) && (indices[0] == 0)) m_matrix = AcGeMatrix3d::translation(offset); //get the handle. If handle is not null it means the end of operation ACHAR handleStr[33]; ZeroMemory(handleStr, 33); AcDbHandle handle; this->getAcDbHandle(handle); if(handle.isNull()) return eOk; handle.getIntoAsciiBuffer(handleStr); close(); // <-- I am closing my entity here. Is it safe? for(int i = 0; i < indices.length(); ++i) { FireGripChanged(handleStr, indices[i]); } return eOk; }
@Juhas0 wrote:Everything works, but my question is - is it safe to close entity in that way?
No, that is not safe. Your code continues to access memory of the closed entity, however there is no guarantee after it is closed that the memory will remain accessible or that the entity will still exist at that location in memory.
So is there any safe workaround? I know, that you can say: "your project is bad designed" 😉 But that is only partially true. This is an old project written using ads and now I'm trying to change it to Object ARX.
As you say, you have to redesign it so that the call to the problematic external function occurs after the grip edit operation is complete and the entity has been closed.