diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-04-21 11:38:30 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-04-21 11:39:34 (GMT) |
commit | 6a3735a47de8a9851e7795cf023d95d81867260d (patch) | |
tree | 9ec461b061ee46936c9cba83ebccdcc698d7b853 /examples | |
parent | 92f07dcd690d596e2d6cc32211c142cd0e25fd97 (diff) | |
download | Qt-6a3735a47de8a9851e7795cf023d95d81867260d.zip Qt-6a3735a47de8a9851e7795cf023d95d81867260d.tar.gz Qt-6a3735a47de8a9851e7795cf023d95d81867260d.tar.bz2 |
BT: Fix lock-up & crash in the Elastic Nodes example
Ensure that we don't divide by 0 when two nodes are exactly on top
of each other.
Reviewed-by: Alexis
Reviewed-by: Joao
Diffstat (limited to 'examples')
-rw-r--r-- | examples/graphicsview/elasticnodes/edge.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/examples/graphicsview/elasticnodes/edge.cpp b/examples/graphicsview/elasticnodes/edge.cpp index 4018c25..e32a35a 100644 --- a/examples/graphicsview/elasticnodes/edge.cpp +++ b/examples/graphicsview/elasticnodes/edge.cpp @@ -93,11 +93,16 @@ void Edge::adjust() QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0)); qreal length = line.length(); - QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length); prepareGeometryChange(); - sourcePoint = line.p1() + edgeOffset; - destPoint = line.p2() - edgeOffset; + + if (!qFuzzyCompare(length, qreal(0.0))) { + QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length); + sourcePoint = line.p1() + edgeOffset; + destPoint = line.p2() - edgeOffset; + } else { + sourcePoint = destPoint = line.p1(); + } } QRectF Edge::boundingRect() const |