draw2d icon indicating copy to clipboard operation
draw2d copied to clipboard

Setting connections vertices crashes the library

Open ms8817 opened this issue 5 years ago • 1 comments

Hi,

Thanks for the very good library. I would like to report a bug which is quite disrupting in terms of usability.

Summary

"Saving" the vertices of a connection as an array of Points and setting them as vertices of a new connection seems to break the application when dragging elements connected to such new connections. More context: I am creating an application where I need to save a diagram to a file and reload it exactly afterwards. To do so, I don't use the marshal and unmarshal functions as they do not suit some of my needs (e.g. I need to restore some non-persistent attributes such as figure labels).

When I "save" a diagram I extract the vertices of all the connections from the vertices attribute of a connection, storing them as an array of Points. Afterwards, I try to load this array of vertices on a new connection by using the setVertices function.

Note that the connections are attached to ports on figures, and such figures are restored precisely with the same dimensions and locations (by saving and setting the x and y attributes of the figures).

The restored connections seems to be fine at first, but when moving the component they are attached to the library seems to crash and it becomes unresponsive (in the figure, the 4 connections should be attached to the component on the left hand side, but they are stuck there as the library crashed). crash

The devTools console repeadetly gives the following error:

RangeError: Maximum call stack size exceeded
    at Array.toString (native)
    at paths (eval at ./node_modules/script-loader/addScript.js.module.exports (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:3671:9), <anonymous>:1563:15)
    at R.pathBBox (eval at ./node_modules/script-loader/addScript.js.module.exports (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:3671:9), <anonymous>:1995:23)
    at Element.elproto.getBBox (eval at ./node_modules/script-loader/addScript.js.module.exports (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:3671:9), <anonymous>:4150:28)
    at Function.R._extractTransform (eval at ./node_modules/script-loader/addScript.js.module.exports (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:3671:9), <anonymous>:2679:43)
    at Element.elproto.transform (eval at ./node_modules/script-loader/addScript.js.module.exports (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:3671:9), <anonymous>:6730:11)
    at Class.applyTransformation (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:40352:16)
    at Class.repaint (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:10562:10)
    at Class.repaint (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:61529:10)
    at Class.prototype.(anonymous function) [as repaint] (eval at ./node_modules/script-loader/addScript.js.module.exports (file:///C:/Users/marco/Documents/Imperial/FIY/app/public/lib/draw2d.js:3671:9), <anonymous>:79:26)

The debugger shows the exception is caught at the end of the onMouseUp function at in the draw2d.policy.canvas.BoundingboxSelectionPolicy object (coincidentally, this is the same place of issue #109). crashCode

Expected behaviour

Connections vertices are loaded properly and can be used without crashes in the application.

Actual behaviour

As described in the summary.

More info

I am using InteractiveManhattanConnectionRouter to route my connections. I also suspect that this may have to do with some sort of floating point issue.

Do not restoring the vertices upon reloading the components fixes the problem, but is highly undesirable as users may have to reposition all the connections.

ms8817 avatar Jun 01 '20 13:06 ms8817

SOLVED

Looking again at this problem: if the connection vertices are set to the correct values after creating the connection, before it is added to the canvas, all seems to work. It appears there is some interaction between the router state and the connection state so that changing connection vertices after adding to the canvas breaks things when the router is invoked to re-route.

tomcl avatar Jul 05 '20 08:07 tomcl