Deleting entity causes segfault

Use this forum for all posts and questions about the free QCAD Community Edition version 3

Moderator: andrew

Post Reply
pimple
Newbie Member
Posts: 3
Joined: Tue Nov 28, 2017 2:36 am

Deleting entity causes segfault

Post by pimple » Sat Dec 02, 2017 9:05 pm

Hi!
I'm working on a script in which I use some lines as a reference, and then I'd like to remove them when I don't need them anymore, but deleting causes QCad to crash... Here's some stripped-down code:

Code: Select all

MyEx.prototype.coordinateEvent = function(event) {
    p1 = event.getModelPosition();

    var docI = this.getDocumentInterface();
    docI.setRelativeZero(p1);

    //Line
    p2 = p1.operator_add(RVector.createPolar(+1.0, RMath.deg2rad(90)));
    line = Line.createLineEntity(this.getDocument(), p1, p2, Line.LineType.Ray);

    //Add line
    var addOp = new RAddObjectsOperation();
    addOp.addObject(line, false);
    docI.applyOperation(addOp);


    //Delete line
    var delOp = new RDeleteObjectsOperation();
    delOp.deleteObject(line);
    docI.applyOperation(delOp);
}
When executed, it causes QCAD to go in segmentation fault. Here's the output (it happens with debugger both enabled or disabled):
Contents$ MacOS/QCAD -enable-script-debugger
QCAD version 3.19.1
20:57:21: Debug: RDxfPlugin::init
Warning: RScriptHandlerEcma::RScriptHandlerEcma: script debugger enabled! Not recommended.
Warning: RScriptHandlerEcma::RScriptHandlerEcma: script debugger enabled! Not recommended.
Segmentation fault: 11
I don't get if I'm doing something wrong, or you simply can't delete entities via a script...
Anyone can help?

Thank You!

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

Re: Deleting entity causes segfault

Post by andrew » Wed Dec 20, 2017 4:54 pm

Please store the ID of the line entity (entity.getId()), not the entity itself. When it comes to deleting the entity, look it up again from the ID (doc.queryEntity) and delete it.

Post Reply

Return to “QCAD Community Edition”