Page 1 of 1

Deleting entity causes segfault

Posted: Sat Dec 02, 2017 9:05 pm
by pimple
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!

Re: Deleting entity causes segfault

Posted: Wed Dec 20, 2017 4:54 pm
by andrew
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.