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. Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format)

Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format)

Scheduled Pinned Locked Moved Unsolved General and Desktop
crashqimagebug
15 Posts 4 Posters 1.9k 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.
  • W Offline
    W Offline
    Wenchi
    wrote on 30 May 2022, 08:10 last edited by Wenchi 6 Aug 2022, 02:58
    #1

    Hello,everyone!

    I'm developing a desktop software with Qt5.15.2. My software rarely will crash. I used .dmp file to track the problem. The Call Stack shows that the crash can happen everywhere while the final crash point is always the same: (the crash function which crashed is: QImageData * QImageData::create(const QSize &size, QImage::Format format) )
    90c30929-61b2-4307-bf77-465d944a5c72-企业微信截图_16538978058027.png

    Is that a Qt Bug? How can I avoid this crash? Even if I had added try catch block to my code where crashed, it still doesn't work.

    Here I post one of the several crashed code and the screenshot of stack:

    void CFuncToolSlamWidget::on_btn_add_clicked()
    {
        //open file
        QString qspath = CViewManager::getInstance()->getFileName(tr("/"), "Image Files(*.jpg;*jpeg;*.png;*.bmp;*.gif)", { "*.bmp","*.jpg","*jpeg","*.png","*.gif" }).trimmed();
        if (qspath.isEmpty())
        {
            return;
        }
        QImage qImaggbk;
        QImageReader reader(qspath);
        reader.setAutoTransform(true);
        qImaggbk = reader.read(); //-------------the crashdump.dmp shows it crashed here-------------------
        if (qImaggbk.width() > 1080 || qImaggbk.height() > 720)
        {
            QImage scaleImage = qImaggbk.scaled(1080, 720, Qt::KeepAspectRatio, Qt::SmoothTransformation);
            int iWidth = scaleImage.width();
            int iheight = scaleImage.height();
    
            bool isSuccess = scaleImage.save(qspath);
        }
        emit signals_select_showType(5, 0, qspath);
        setSignButtonStatus(false);
    }
    

    3710c93c-cb56-4032-a8b3-bdd68f75c34e-企业微信截图_16539031684199.png

    J 1 Reply Last reply 30 May 2022, 08:22
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 30 May 2022, 08:19 last edited by
      #2

      Look where in your code the crash comes from and post the code (not screenshot). Also make sure the QImage data is valid during the whole lifetime of the QImage object (which I doubt it is) - how do you create your QImage object?

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

      W 1 Reply Last reply 30 May 2022, 09:36
      3
      • W Wenchi
        30 May 2022, 08:10

        Hello,everyone!

        I'm developing a desktop software with Qt5.15.2. My software rarely will crash. I used .dmp file to track the problem. The Call Stack shows that the crash can happen everywhere while the final crash point is always the same: (the crash function which crashed is: QImageData * QImageData::create(const QSize &size, QImage::Format format) )
        90c30929-61b2-4307-bf77-465d944a5c72-企业微信截图_16538978058027.png

        Is that a Qt Bug? How can I avoid this crash? Even if I had added try catch block to my code where crashed, it still doesn't work.

        Here I post one of the several crashed code and the screenshot of stack:

        void CFuncToolSlamWidget::on_btn_add_clicked()
        {
            //open file
            QString qspath = CViewManager::getInstance()->getFileName(tr("/"), "Image Files(*.jpg;*jpeg;*.png;*.bmp;*.gif)", { "*.bmp","*.jpg","*jpeg","*.png","*.gif" }).trimmed();
            if (qspath.isEmpty())
            {
                return;
            }
            QImage qImaggbk;
            QImageReader reader(qspath);
            reader.setAutoTransform(true);
            qImaggbk = reader.read(); //-------------the crashdump.dmp shows it crashed here-------------------
            if (qImaggbk.width() > 1080 || qImaggbk.height() > 720)
            {
                QImage scaleImage = qImaggbk.scaled(1080, 720, Qt::KeepAspectRatio, Qt::SmoothTransformation);
                int iWidth = scaleImage.width();
                int iheight = scaleImage.height();
        
                bool isSuccess = scaleImage.save(qspath);
            }
            emit signals_select_showType(5, 0, qspath);
            setSignButtonStatus(false);
        }
        

        3710c93c-cb56-4032-a8b3-bdd68f75c34e-企业微信截图_16539031684199.png

        J Offline
        J Offline
        JonB
        wrote on 30 May 2022, 08:22 last edited by
        #3

        @Wenchi
        It is probably your code bug rather than Qt code. I believe the screenshot shows that the d in d->nbytes is currently nullptr. try...catch won't trap it.

        You need a stack trace showing where this call to QImageData::create() originates from in your code. I do not know whether crashdump.dmp can show you that. If you compile for debug and run under whatever debugger for your compiler under Windows you should be able to see that stack trace when it happens?

        1 Reply Last reply
        0
        • C Christian Ehrlicher
          30 May 2022, 08:19

          Look where in your code the crash comes from and post the code (not screenshot). Also make sure the QImage data is valid during the whole lifetime of the QImage object (which I doubt it is) - how do you create your QImage object?

          W Offline
          W Offline
          Wenchi
          wrote on 30 May 2022, 09:36 last edited by Wenchi
          #4

          @Christian-Ehrlicher @JonB
          Thank you for your reply! I have updated the description of my question. Could you see whether the information is enough. Since I haven't read the book, <Advanced Windows Debugging>, I'm afraid I couldn't provide more debug infomation.

          J 1 Reply Last reply 30 May 2022, 09:57
          0
          • W Wenchi
            30 May 2022, 09:36

            @Christian-Ehrlicher @JonB
            Thank you for your reply! I have updated the description of my question. Could you see whether the information is enough. Since I haven't read the book, <Advanced Windows Debugging>, I'm afraid I couldn't provide more debug infomation.

            J Offline
            J Offline
            JonB
            wrote on 30 May 2022, 09:57 last edited by JonB
            #5

            @Wenchi
            So the trace shows you clicked a button and it called your CFuncToolSlamWidget::on_btn_add_clicked(). At line #263 that calls QImageReader::read(). So let's see the code around (i.e. leading up to) that line #263. We are probably particularly interested in the lifetime of the QImage you are using.

            W 1 Reply Last reply 30 May 2022, 10:19
            0
            • J JonB
              30 May 2022, 09:57

              @Wenchi
              So the trace shows you clicked a button and it called your CFuncToolSlamWidget::on_btn_add_clicked(). At line #263 that calls QImageReader::read(). So let's see the code around (i.e. leading up to) that line #263. We are probably particularly interested in the lifetime of the QImage you are using.

              W Offline
              W Offline
              Wenchi
              wrote on 30 May 2022, 10:19 last edited by
              #6

              @JonB
              I have already uploaded the code of function
              void CFuncToolSlamWidget::on_btn_add_clicked()
              to the description of the question.
              And the crash line is
              qImaggbk = reader.read();
              Since the crash doesn't appear necessarily, I couldn't figure out why it crashed.

              J 1 Reply Last reply 30 May 2022, 10:27
              0
              • W Wenchi
                30 May 2022, 10:19

                @JonB
                I have already uploaded the code of function
                void CFuncToolSlamWidget::on_btn_add_clicked()
                to the description of the question.
                And the crash line is
                qImaggbk = reader.read();
                Since the crash doesn't appear necessarily, I couldn't figure out why it crashed.

                J Offline
                J Offline
                JonB
                wrote on 30 May 2022, 10:27 last edited by
                #7

                @Wenchi
                Then it looks like QImageReader::read() does not like the content of the .png file you are trying to load. Does it happen depending on which file is chosen? Try the code with a specified filename in some standalone code outside of your project and see how it goes?

                W 1 Reply Last reply 31 May 2022, 03:38
                2
                • JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on 30 May 2022, 14:30 last edited by JoeCFD
                  #8

                  Try to use another tool to load your image and see if the file is corrupt or has some other issues. It may be a good idea to check if read() fails or not all the time like the following:

                  QImage icon(64, 64, QImage::Format_RGB32);
                  QImageReader reader("icon_64x64.bmp");
                  if (reader.read(&icon)) {
                      // Display icon
                  }
                  

                  the sample code is from here:
                  https://doc.qt.io/qt-5/qimagereader.html#read-1

                  W 1 Reply Last reply 31 May 2022, 03:48
                  1
                  • J JonB
                    30 May 2022, 10:27

                    @Wenchi
                    Then it looks like QImageReader::read() does not like the content of the .png file you are trying to load. Does it happen depending on which file is chosen? Try the code with a specified filename in some standalone code outside of your project and see how it goes?

                    W Offline
                    W Offline
                    Wenchi
                    wrote on 31 May 2022, 03:38 last edited by
                    #9

                    @JonB
                    I've tried that before. I coded while{...} to load the picture(png), which had caused crash, for over 1 million times, but the crash didn't appear.

                    1 Reply Last reply
                    0
                    • JoeCFDJ JoeCFD
                      30 May 2022, 14:30

                      Try to use another tool to load your image and see if the file is corrupt or has some other issues. It may be a good idea to check if read() fails or not all the time like the following:

                      QImage icon(64, 64, QImage::Format_RGB32);
                      QImageReader reader("icon_64x64.bmp");
                      if (reader.read(&icon)) {
                          // Display icon
                      }
                      

                      the sample code is from here:
                      https://doc.qt.io/qt-5/qimagereader.html#read-1

                      W Offline
                      W Offline
                      Wenchi
                      wrote on 31 May 2022, 03:48 last edited by
                      #10

                      @JoeCFD
                      Thank you for your reply!
                      Using another tool to load image can be a way to avoid the crash, but in my situstion, the crash could appear not only in QImageReader.read() but also in several other code, such as Qlist<MyWidget>.push_back() or QStackWidget.setCurrentIndex() and so on.

                      C 1 Reply Last reply 31 May 2022, 15:32
                      0
                      • W Wenchi
                        31 May 2022, 03:48

                        @JoeCFD
                        Thank you for your reply!
                        Using another tool to load image can be a way to avoid the crash, but in my situstion, the crash could appear not only in QImageReader.read() but also in several other code, such as Qlist<MyWidget>.push_back() or QStackWidget.setCurrentIndex() and so on.

                        C Offline
                        C Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 31 May 2022, 15:32 last edited by
                        #11

                        @Wenchi said in Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format):

                        the crash could appear not only in QImageReader.read() but also in several other code, such as Qlist<MyWidget>.push_back() or QStackWidget.setCurrentIndex() and so on.

                        Then you should fix your code.

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

                        1 Reply Last reply
                        0
                        • W Offline
                          W Offline
                          Wenchi
                          wrote on 6 Jun 2022, 09:00 last edited by
                          #12

                          please help!I'll lose my job if I can't fix this bug. crying

                          J 1 Reply Last reply 6 Jun 2022, 10:14
                          0
                          • W Wenchi
                            6 Jun 2022, 09:00

                            please help!I'll lose my job if I can't fix this bug. crying

                            J Offline
                            J Offline
                            JonB
                            wrote on 6 Jun 2022, 10:14 last edited by
                            #13

                            @Wenchi
                            How do you expect anybody to offer any further help, if your code is crashing in various places?

                            W 1 Reply Last reply 7 Jun 2022, 07:44
                            0
                            • J JonB
                              6 Jun 2022, 10:14

                              @Wenchi
                              How do you expect anybody to offer any further help, if your code is crashing in various places?

                              W Offline
                              W Offline
                              Wenchi
                              wrote on 7 Jun 2022, 07:44 last edited by Wenchi 6 Aug 2022, 10:08
                              #14

                              @JonB
                              Although the code is crashing in various places, the crash point is always the same:

                              QImageData * QImageData::create(const QSize &size, QImage::Format format) )
                              

                              by the way, I'm fired. ready to get a new start

                              J 1 Reply Last reply 7 Jun 2022, 08:24
                              0
                              • W Wenchi
                                7 Jun 2022, 07:44

                                @JonB
                                Although the code is crashing in various places, the crash point is always the same:

                                QImageData * QImageData::create(const QSize &size, QImage::Format format) )
                                

                                by the way, I'm fired. ready to get a new start

                                J Offline
                                J Offline
                                JonB
                                wrote on 7 Jun 2022, 08:24 last edited by JonB 6 Jul 2022, 08:25
                                #15

                                @Wenchi said in Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format):

                                Although the code is crashing in various places, but the crash point is always the same:

                                But that is likely --- or just as possible --- indicating you have a problem elsewhere which only shows up here, such as corrupted/misallocated memory? How else would you explain it "crashing" in e.g. QList<MyWidget>.push_back()?

                                by the way, I'm fired. ready to get a new start

                                I am sorry to hear that, good luck for future.

                                1 Reply Last reply
                                1

                                1/15

                                30 May 2022, 08:10

                                • Login

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