Deleting entity segfaults

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

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
User avatar
andrew
Site Admin
Posts: 9058
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: 9058
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 Programming, Script Programming and Contributing”