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. QVideoFrame Crash on map - unmap
QtWS25 Last Chance

QVideoFrame Crash on map - unmap

Scheduled Pinned Locked Moved Solved General and Desktop
qvideoframe
8 Posts 2 Posters 3.0k 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.
  • A Offline
    A Offline
    amahta
    wrote on 22 Oct 2015, 09:50 last edited by
    #1

    I have this function in my code and I am trying to show a frame of a video feed on a QLabel. I have subclassed QAbstractVideoSurface and pass the QVideoFrame using a signal. When I use the debugger it seems everything here gets done without any problems. But it crashes right after this.

    Any ideas?

    void MainWindow::onFrameAvailable(const QVideoFrame &frame)
    {
    QVideoFrame cloneFrame(frame);
    cloneFrame.map(QAbstractVideoBuffer::ReadOnly);

    const QImage image(cloneFrame.bits(),
                       cloneFrame.width(),
                       cloneFrame.height(),
                       QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat()));
    
    cloneFrame.unmap();
    ui->videoLabel->setPixmap(QPixmap::fromImage(image));
    

    }

    Thou shalt programme
    http://www.amin-ahmadi.com

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Oct 2015, 10:03 last edited by
      #2

      Hi,

      Your QImage relies on the data from cloneFrame. Since you unmap cloneFrame before using your image, it now tries to access data that are not valid anymore. See the constructor documentation about the lifetime of the data passed as parameter.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 22 Oct 2015, 10:49
      0
      • S SGaist
        22 Oct 2015, 10:03

        Hi,

        Your QImage relies on the data from cloneFrame. Since you unmap cloneFrame before using your image, it now tries to access data that are not valid anymore. See the constructor documentation about the lifetime of the data passed as parameter.

        A Offline
        A Offline
        amahta
        wrote on 22 Oct 2015, 10:49 last edited by
        #3

        @SGaist said:

        Hi,

        Your QImage relies on the data from cloneFrame. Since you unmap cloneFrame before using your image, it now tries to access data that are not valid anymore. See the constructor documentation about the lifetime of the data passed as parameter.

        Uh my mistake. Thanks @SGaist . I used QImage::copy() method to copy it into a persistent memory space and now it's fine!

        Thou shalt programme
        http://www.amin-ahmadi.com

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 22 Oct 2015, 11:55 last edited by
          #4

          If you only make the pixmap from the image, then moving the call to unmap after you're done is enough. That avoids a useless copy.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 2 Replies Last reply 22 Oct 2015, 12:02
          0
          • S SGaist
            22 Oct 2015, 11:55

            If you only make the pixmap from the image, then moving the call to unmap after you're done is enough. That avoids a useless copy.

            A Offline
            A Offline
            amahta
            wrote on 22 Oct 2015, 12:02 last edited by amahta
            #5

            @SGaist said:

            If you only make the pixmap from the image, then moving the call to unmap after you're done is enough. That avoids a useless copy.

            Actually that was what I tried at first but it crashed again so I assumed QPixmap is also using the same space in the memory?! (Not so sure about this)

            Thou shalt programme
            http://www.amin-ahmadi.com

            1 Reply Last reply
            0
            • S SGaist
              22 Oct 2015, 11:55

              If you only make the pixmap from the image, then moving the call to unmap after you're done is enough. That avoids a useless copy.

              A Offline
              A Offline
              amahta
              wrote on 22 Oct 2015, 12:04 last edited by
              #6

              @SGaist but you're right the performance will drop because of the useless copy!

              Thou shalt programme
              http://www.amin-ahmadi.com

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 22 Oct 2015, 20:54 last edited by
                #7

                You can also copy the pixmap itself, it might be faster.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                A 1 Reply Last reply 22 Oct 2015, 21:10
                0
                • S SGaist
                  22 Oct 2015, 20:54

                  You can also copy the pixmap itself, it might be faster.

                  A Offline
                  A Offline
                  amahta
                  wrote on 22 Oct 2015, 21:10 last edited by
                  #8

                  @SGaist I'll give it a try! Thanks for the help anyway.

                  Thou shalt programme
                  http://www.amin-ahmadi.com

                  1 Reply Last reply
                  0

                  8/8

                  22 Oct 2015, 21:10

                  • Login

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