ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Closing my entity in subMoveGripPointsAt

3 REPLIES 3
Reply
Message 1 of 4
Juhas0
367 Views, 3 Replies

Closing my entity in subMoveGripPointsAt

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;
}

 

Tags (2)
3 REPLIES 3
Message 2 of 4
owenwengerd
in reply to: Juhas0


@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.

--
Owen Wengerd
ManuSoft
Message 3 of 4
Juhas0
in reply to: owenwengerd

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.

Message 4 of 4
owenwengerd
in reply to: Juhas0

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.

--
Owen Wengerd
ManuSoft

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost