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. QtConcurrent mapped crashes
QtWS25 Last Chance

QtConcurrent mapped crashes

Scheduled Pinned Locked Moved Unsolved General and Desktop
concurrent
16 Posts 4 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.
  • A Offline
    A Offline
    akshaybabloo
    wrote on last edited by
    #1

    I am trying to use the example shown in https://doc.qt.io/qt-6/qtconcurrentmap.html#concurrent-map

    My code is very much similar to the one shown in the link above,

    Code:

    QImage ImageFormatter::createImageCollage(ImageData *imageData) {
    
        QFuture<QImage> future = QtConcurrent::mapped(imageData->getFrames(), ImageFormatter::scaled);
        auto item = future.then([](const QImage& reply){
            qDebug() << reply;
        });
    
        return {};
    }
    
    QImage ImageFormatter::scaled(const QImage &image) {
        qDebug() << image;
        return image.scaled(100,100);
    }
    

    The app crashes at image.scaled(100,100). I have no idea why. There is no error code too.

    imageData->getFrames() returns QList<QImage>.

    Any help on this is appreciated.

    jsulmJ 1 Reply Last reply
    0
    • A akshaybabloo

      I am trying to use the example shown in https://doc.qt.io/qt-6/qtconcurrentmap.html#concurrent-map

      My code is very much similar to the one shown in the link above,

      Code:

      QImage ImageFormatter::createImageCollage(ImageData *imageData) {
      
          QFuture<QImage> future = QtConcurrent::mapped(imageData->getFrames(), ImageFormatter::scaled);
          auto item = future.then([](const QImage& reply){
              qDebug() << reply;
          });
      
          return {};
      }
      
      QImage ImageFormatter::scaled(const QImage &image) {
          qDebug() << image;
          return image.scaled(100,100);
      }
      

      The app crashes at image.scaled(100,100). I have no idea why. There is no error code too.

      imageData->getFrames() returns QList<QImage>.

      Any help on this is appreciated.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @akshaybabloo said in QtConcurrent mapped crashes:

      There is no error code too

      What about running through debugger to see what happens?
      You should at least check whether the image is not null image: https://doc.qt.io/qt-5/qimage.html#isNull

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      1
      • jsulmJ jsulm

        @akshaybabloo said in QtConcurrent mapped crashes:

        There is no error code too

        What about running through debugger to see what happens?
        You should at least check whether the image is not null image: https://doc.qt.io/qt-5/qimage.html#isNull

        A Offline
        A Offline
        akshaybabloo
        wrote on last edited by
        #3

        @jsulm I got an popup window that says - Stopped in thread 13 by: Exception at 0x7ff97c36bdda, code: 0xc0000005: read access violation at: 0x1b39f8c42ba, flags=0x0 (first chance).

        And the console shows:

        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(10) tid(14090) 80070490 Element not found.
        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(11) tid(14090) 80070490 Element not found.
        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(12) tid(14090) 80070490 Element not found.
        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(13) tid(14090) 80070490 Element not found.
        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(14) tid(14090) 80070490 Element not found.
        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(15) tid(14090) 80070490 Element not found.
        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(16) tid(14090) 80070490 Element not found.
        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(17) tid(14090) 80070490 Element not found.
        onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(18) tid(14090) 80070490 Element not found.
        
        jsulmJ 1 Reply Last reply
        0
        • A akshaybabloo

          @jsulm I got an popup window that says - Stopped in thread 13 by: Exception at 0x7ff97c36bdda, code: 0xc0000005: read access violation at: 0x1b39f8c42ba, flags=0x0 (first chance).

          And the console shows:

          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(10) tid(14090) 80070490 Element not found.
          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(11) tid(14090) 80070490 Element not found.
          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(12) tid(14090) 80070490 Element not found.
          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(13) tid(14090) 80070490 Element not found.
          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(14) tid(14090) 80070490 Element not found.
          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(15) tid(14090) 80070490 Element not found.
          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(16) tid(14090) 80070490 Element not found.
          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(17) tid(14090) 80070490 Element not found.
          onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(18) tid(14090) 80070490 Element not found.
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @akshaybabloo Please show the stack trace.
          And what about my other suggestion?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @akshaybabloo Please show the stack trace.
            And what about my other suggestion?

            A Offline
            A Offline
            akshaybabloo
            wrote on last edited by
            #5

            @jsulm I did check if the image is null or not.

            Screenshot 2022-01-07 204054.png

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Your stacktrace shows a VideoSequencer class or function but your code does not.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              A 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                Your stacktrace shows a VideoSequencer class or function but your code does not.

                A Offline
                A Offline
                akshaybabloo
                wrote on last edited by
                #7

                @Christian-Ehrlicher Sorry. What does that mean?

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Your code and your stack imo trace to not match. Compile your app in debug mode and show the back trace again. There must be line numbers for your code in the stack trace, not just for Qt.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  A 3 Replies Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    Your code and your stack imo trace to not match. Compile your app in debug mode and show the back trace again. There must be line numbers for your code in the stack trace, not just for Qt.

                    A Offline
                    A Offline
                    akshaybabloo
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher When I try to do that, I get - This does not seem to be a "Debug" build. Setting breakpoints by file name and line number may fail. and I am in a Debug profile

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      Your code and your stack imo trace to not match. Compile your app in debug mode and show the back trace again. There must be line numbers for your code in the stack trace, not just for Qt.

                      A Offline
                      A Offline
                      akshaybabloo
                      wrote on last edited by
                      #10

                      @Christian-Ehrlicher I tried to change the build type to Debug and now I get error in build settings as (screenshot):

                      Screenshot 2022-01-08 092552.png

                      Debug initial parameters are:

                      -GNinja
                      -DCMAKE_BUILD_TYPE:STRING=Debug
                      -DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
                      -DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}
                      -DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}
                      -DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}
                      -DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
                      
                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        Your code and your stack imo trace to not match. Compile your app in debug mode and show the back trace again. There must be line numbers for your code in the stack trace, not just for Qt.

                        A Offline
                        A Offline
                        akshaybabloo
                        wrote on last edited by
                        #11

                        @Christian-Ehrlicher Never mind. The issue was with Conan. I got it working now.

                        And here is the screenshot:

                        Screenshot 2022-01-08 100857.png

                        Also added a small change:

                        QImage ImageFormatter::scaled(const QImage &image) {
                            if (image.isNull()){
                                qDebug()<<image;
                                return image;
                            }
                            return image.scaled(100,100);
                        }
                        
                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Ok, better now.
                          And you're sure the QImage is not touched from outside in another thread? Please take a look what the other threads are doing while it crashes. Is imageData still valid during the lifetime of QtConcurrent::mapped()?

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          A 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            Ok, better now.
                            And you're sure the QImage is not touched from outside in another thread? Please take a look what the other threads are doing while it crashes. Is imageData still valid during the lifetime of QtConcurrent::mapped()?

                            A Offline
                            A Offline
                            akshaybabloo
                            wrote on last edited by
                            #13

                            @Christian-Ehrlicher As far as I know, no. I am doing this only after creating the list of ImageData. The getters has [[nodiscard]] attribute. I am also using OpenCV to read in the video files and converting them into frames, but this is flushed after getting the frames.

                            The code can be found at https://github.com/akshaybabloo/VideoSequencer

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              data->appendFrame(QImage(frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888));

                              Default problem not reading the QImage documentation...

                              The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              A 1 Reply Last reply
                              3
                              • Christian EhrlicherC Christian Ehrlicher

                                data->appendFrame(QImage(frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888));

                                Default problem not reading the QImage documentation...

                                The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.

                                A Offline
                                A Offline
                                akshaybabloo
                                wrote on last edited by
                                #15

                                @Christian-Ehrlicher I have no idea what that means 😅

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  Hi,

                                  You create a QImage out of an OpenCV Mat object. The constructor you use for that explicitly does not copy the data from the Mat object. This is what the warning is all about. It is your job to ensure that the Mat object lifetime is longer than the one of of your QImage.

                                  Or you should explicitly trigger a copy of the QImage object when adding it to your array.

                                  What happens is that when you do your concurrent call is that Mat object that used went out of scope and thus the QImage internal structure is now pointing to invalid data.

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

                                  1 Reply Last reply
                                  3

                                  • Login

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