From 7a4e9d2e834ae131d05981392985ce1257422a38 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Tue, 10 Nov 2015 13:20:03 +0100 Subject: [PATCH] Removed UBGraphicsPolygonItem::shape() Long version: UBGraphicsPolygonItem::shape() sometimes caused OpenBoard to crash due to inifinite recursion. This is easily replicated by trying to use the highlighting tool. The reason is: shape() calls boundingRect(); this function's definition is: QRectF QGraphicsPolygonItem::boundingRect() const { Q_D(const QGraphicsPolygonItem); if (d->boundingRect.isNull()) { qreal pw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF(); if (pw == 0.0) d->boundingRect = d->polygon.boundingRect(); else d->boundingRect = shape().controlPointRect(); } return d->boundingRect; } In the case where pw != 0, the shape() function is called. However, it is shape() from the derived class, not the base class, which is called. In other words, UBGraphicsPolygonItem::shape() is called rather than QGraphicsPolygonItem::shape(). This means that boundingRect() is called again from within shape(), and so on, causing the program to crash. The fix was simply to remove UBGraphicsPolygonItem::shape(), as it appears to provide the same (or very similar) functionality to that of the base class's shape() function. In case this shape() function actually is needed, another workaround should be implemented to prevent this infinite recursion. --- src/domain/UBGraphicsPolygonItem.cpp | 10 ---------- src/domain/UBGraphicsPolygonItem.h | 1 - 2 files changed, 11 deletions(-) diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index bfbd515e..1f5b40c3 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -211,16 +211,6 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi QGraphicsPolygonItem::paint(painter, option, widget); } -QPainterPath UBGraphicsPolygonItem::shape() const -{ - - QPainterPath path; - path.addRect(boundingRect()); - - return path; -} - - UBGraphicsScene* UBGraphicsPolygonItem::scene() { return qobject_cast(QGraphicsPolygonItem::scene()); diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 1296b65d..600e4598 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -132,7 +132,6 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem protected: void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); - QPainterPath shape () const; private: