Deleting entity segfaults

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Post Reply
User avatar
andrew
Site Admin
Posts: 6503
Joined: Fri Mar 30, 2007 6:07 am

Deleting entity segfaults

Post by andrew » Fri Oct 18, 2019 8:15 am

From a QCAD user:
Why does this code segfault?

Code: Select all

var op = new RAddObjectsOperation();
op.addObject(entity);
di.applyOperation(op);

...

op = new RAddObjectsOperation();
op.deleteObject(entity);
di.applyOperation(op);

User avatar
andrew
Site Admin
Posts: 6503
Joined: Fri Mar 30, 2007 6:07 am

Re: Deleting entity segfaults

Post by andrew » Fri Oct 18, 2019 8:16 am

Entity pointers should not be used more than once in an operation. If you need to apply an operation on the same entity, you need to retrieve a new pointer first:

Code: Select all

var op = new RAddObjectsOperation();
op.addObject(entity);
di.applyOperation(op);
var id = entity.getId();

...

op = new RAddObjectsOperation();
entity = doc.queryEntity(id);
op.deleteObject(entity);
di.applyOperation(op);

Post Reply

Return to “QCAD Developers and Contributors”