Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21786

No or wrong painting due to integer overflows in QGraphicsScene while handling large items/big scales

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 4.7.3, 4.7.4, 4.8.0, 5.3.1
    • Widgets: GraphicsView
    • None
    • Should occur on all platforms with <= 32bit integers. Tested on Windows XP / Windows 7 + MSVC10 with Qt 4.7.3, 4.7.4 as well as Qt 4.8.0 RC1. Also Windows 8.1 and Qt 5.3.1.

    Description

      A scene fails to correctly draw itself when a scale is applied that would make the width or height of an item's bounding box bigger or close to INT_MAX when scaled to view coordinates.

      One problematic location in the source is in qgraphicsscene.cpp lines 4792ff:

      QRect viewBoundingRect = translateOnlyTransform ? brect.translated(transformPtr->dx(), transformPtr->dy()).toAlignedRect() : transformPtr->mapRect(brect).toAlignedRect();
      viewBoundingRect.adjust(-int(rectAdjust), -int(rectAdjust), rectAdjust, rectAdjust);

      toAlignedRect() will stop returning sensible results as soon as xp+w or yp+h of the rect exceeds integer range. Of course the QRect itself will never hold anything that exceeds INT_MAX in w or h. Moving around the rect with adjust is limited the same way. This results in the intersection returning invalid results that lead to items not be being drawn when they should be.

      Also there seems to be another wraparound issue when drawing big rectangles / lines (in QPainter?) but I have not looked into that.

      You can see both issues in the attached sample. The different _view->scale values expose different manifestations of the problem. Run with either one (or none) of them and scroll around a bit. The vertical line marks the 0 x position and both rects expand to the right. Depending on the scale you should see rects being drawn from 0 extending into negative space instead of positive and/or rects not drawn at all if scrolling to the right.

      Attachments

        1. main.cpp
          2 kB
        2. main-qt-5.15.1.cpp
          2 kB
        3. main-qt5.cpp
          1 kB
        4. no-line.png
          no-line.png
          3 kB
        5. screenshot_two_rects_overflow.png
          screenshot_two_rects_overflow.png
          4 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            stefanh Stefan Hacker
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes