Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Program crashes on QPainter::drawPixmap()
QtWS25 Last Chance

Program crashes on QPainter::drawPixmap()

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    j_omega
    wrote on last edited by A Former User
    #1

    I am having problem where my Qt program crashes after calling QPainter::drawPixmap(). I have spent 2 days debugging this and have decided that I must be unintentionally abusing some feature of Qt.

    A working example of this problem can be found here.

    My code consists of a QML file that updates the following properteries:

    Q_PROPERTY(qreal longitude READ getLongitude WRITE setLongitude NOTIFY latitudeChanged)
    Q_PROPERTY(qreal latitude READ getLatitude WRITE setLatitude NOTIFY latitudeChanged)
    
    void Map::setLongitude(qreal longitude)
    {
        double diff = (this->longitude - this->pixmapCenter.longitude()) * scale;
        this->longitude = longitude;
    
        if (qFabs(diff) > 50)
        {
            MapTile result = updatePixmap(scale, longitude, latitude);
            pixmap = result.pixmap;
            pixmapCenter = result.center;
        }
        update();
    }
    
    void Map::setLatitude(qreal latitude)
    {
        this->latitude = latitude;
    }
    

    That in turn regenerates a new Pixmap

    MapTile updatePixmap(double scale, double longitude, double latitude)
    {
    
        QPixmap myPixmap(800, 400);
        myPixmap.fill(Qt::transparent);
        QPainter painter(&myPixmap);
        painter.translate(400, 240);
        QPen pen;
    
        pen.setColor(Qt::white);
        pen.setWidth(1);
        painter.setPen(pen);
        QRectF boundaries(QPointF(-91.55 , 41.55) * scale,
                         QPointF(-91.45, 41.45) * scale);
        boundaries.translate(-longitude * scale, -latitude * scale);
        painter.drawRect(boundaries);
        painter.end();
    
        QGeoCoordinate center(latitude, longitude);
        return MapTile(myPixmap, center);
    }
    

    This new pixmap is then drawn on the screen at the appropriate location. It is important to note that the program runs fine for a few seconds before it crashes.

    It crashes with a segfault error in qdrawhelper_sse2.cpp line 587.

    void Map::paint(QPainter *painter)
    {
        painter->translate(boundingRect().width()/2, boundingRect().height()/2);
        painter->scale(1, -1);
    
        painter->translate((pixmapCenter.longitude() - longitude) * scale,
                           (pixmapCenter.latitude() - latitude) * scale);
        QPoint corner(-pixmap.width()/2, -pixmap.height()/2);
    
        painter->drawPixmap(corner, this->pixmap);
    
    }
    

    Here is an image of the moment of the crash

    enter image description here

    enter image description here

    1 Reply Last reply
    0
    • J Offline
      J Offline
      j_omega
      wrote on last edited by
      #5

      It turns out this is a bug. See here.

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #2

        What's in line 42 of Map::paint?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        raven-worxR 1 Reply Last reply
        0
        • VRoninV VRonin

          What's in line 42 of Map::paint?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #3

          @VRonin said in Qt program crashes on QPainter::drawPixmap():

          What's in line 42 of Map::paint?

          https://github.com/kyle7119/stackoverflow_question/blob/master/map.cpp#L42

          @j_omega
          You debug window says "Source file is more recent than executable"
          Can you try a full rebuild (clean & build)

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          J 1 Reply Last reply
          1
          • raven-worxR raven-worx

            @VRonin said in Qt program crashes on QPainter::drawPixmap():

            What's in line 42 of Map::paint?

            https://github.com/kyle7119/stackoverflow_question/blob/master/map.cpp#L42

            @j_omega
            You debug window says "Source file is more recent than executable"
            Can you try a full rebuild (clean & build)

            J Offline
            J Offline
            j_omega
            wrote on last edited by j_omega
            #4

            @raven-worx I saw that earlier and already tried the a clean/rebuild. I even deleted the entire project and cloned the repo again.

            I just noticed that this does not happen in release configuration. I have submitted a Qt bug report.

            My environment is MinGW 5.3.0 on Windows 7 (or 10)

            1 Reply Last reply
            0
            • J Offline
              J Offline
              j_omega
              wrote on last edited by
              #5

              It turns out this is a bug. See here.

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved