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. Problem loading big Tiff Files
Forum Updated to NodeBB v4.3 + New Features

Problem loading big Tiff Files

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 4.4k Views 3 Watching
  • 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi
    How big are those tiff?
    A 32 bit process is limited to 2-3 GB
    https://blogs.msdn.microsoft.com/tom/2008/04/10/chat-question-memory-limits-for-32-bit-and-64-bit-processes/

    So it has to be huge TIFFs or app used lots of memory for other stuff , then
    it is indeed possible to be related to memory.

    Have you watched your apps mem use under windows?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      euchkatzl
      wrote on last edited by
      #3

      Memory Usage is between 700 and 800 MB in Task Manager.

      mrjjM 1 Reply Last reply
      0
      • E euchkatzl

        Memory Usage is between 700 and 800 MB in Task Manager.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @euchkatzl
        ok so it does seem like there is plenty of memory left.

        Is the call stackalways the same when it crashes?

        1 Reply Last reply
        0
        • E Offline
          E Offline
          euchkatzl
          wrote on last edited by
          #5

          Yes. Always one of these two mentioned in the Screenshots

          mrjjM 1 Reply Last reply
          0
          • E euchkatzl

            Yes. Always one of these two mentioned in the Screenshots

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @euchkatzl
            It does seems it crash inside Qt which is odd.

            Lets see if some of the other mods have any
            good ides from the call stack.

            I assume testing with the tiff alone dont crash anything. only in full program?

            1 Reply Last reply
            0
            • E Offline
              E Offline
              euchkatzl
              wrote on last edited by
              #7

              The Tiffs are about 70 MB per file.

              It seems to crash in the Qt Module yes. That is why i posted this.

              Loading the tiff in a standalone program don't crash.

              1 Reply Last reply
              0
              • E Offline
                E Offline
                euchkatzl
                wrote on last edited by
                #8

                I even don't understand what is the connection between QWebEngineCore and QSqlQuery/ QImageReader.

                Thats wired.

                kshegunovK 1 Reply Last reply
                0
                • E euchkatzl

                  I even don't understand what is the connection between QWebEngineCore and QSqlQuery/ QImageReader.

                  Thats wired.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #9

                  @euchkatzl
                  Hi,
                  How are you loading them, and into what? Are you using QPixmap? And what SQL plugin are you using?

                  Kind regards.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  1
                  • E Offline
                    E Offline
                    euchkatzl
                    wrote on last edited by
                    #10

                    The Images are loaded in a background Thread . Therefore QImage is used because QPixmaps can only be constructed in Gui Thread.

                    QImage ImageHelper::scaledImageFromImageData(const QByteArray &imageData, const QSize &size, const QRect &source, bool *oIsSvg, QSize *oSize) {
                    //    TraceLine t("scaleLoad");
                        QTransform ot = orientationTransform(imageData);
                        bool isSvg = isSvgImageData(imageData);
                        if (oIsSvg) *oIsSvg = isSvg;
                    
                        QSize scaledSize = size;
                        QRect clipRect = source;
                        if (!ot.isIdentity()) {
                            scaledSize = ot.mapRect(QRect(QPoint(), scaledSize)).size();
                            if (!clipRect.isEmpty()) {
                                clipRect = QRect();
                    //            QTransform t;
                    //            t.translate(size.width()/2.0,size.height()/2.0);
                    //            t *= ot;
                    //            t.translate(-size.width()/2.0,-size.height()/2.0);
                    //            clipRect = t.mapRect(clipRect);
                            }
                        }
                    
                        QByteArray data = imageData;
                        QBuffer buff(&data);
                        QImageReader reader(&buff);
                        if (!reader.supportsOption(QImageIOHandler::Size)) {
                            qDebug() << "ImageHelper::scaledImageFromImageData() can not determine image original size";
                        }
                        QSize orgSize = reader.size();
                        if(oSize){
                            *oSize = orgSize;
                        }
                        if (!clipRect.isEmpty()) {
                            qreal dx = qreal(orgSize.width())/scaledSize.width();
                            qreal dy = qreal(orgSize.height())/scaledSize.height();
                            QRect clip = QTransform::fromScale(dx, dy).mapRect(QRectF(clipRect)).toAlignedRect();
                            reader.setClipRect(clip);
                            reader.setScaledSize(clipRect.size());
                        } else {
                            reader.setScaledSize(scaledSize);
                        }
                    //    TraceLine *kk = new TraceLine("read");
                        QImage img = reader.read();
                        if(!img.isNull()){
                        //    delete kk;
                            if (!ot.isIdentity()) {
                                img = img.transformed(ot, Qt::SmoothTransformation);
                                QSize is = img.size();
                                if (is != size) {
                                    qDebug() << "transformatino error";
                                }
                                if (!source.isEmpty()) {
                                    img = img.copy(source);
                                }
                            }
                            QSize is = img.size();
                            if (!source.isEmpty()) {
                                Q_ASSERT(is == source.size());
                            } else {
                                Q_ASSERT(is == size);
                            }
                        }
                        return img;
                    }
                    

                    The Crash always occurs on the line :

                    QImage img = reader.read();
                    

                    The ByteArray used in this function is loaded via the SqlLite Database Plugin.

                    I really think this is a memory allocating problem. But i don't understand why QWebEngine is in the Stack Trace

                    kshegunovK 1 Reply Last reply
                    0
                    • E euchkatzl

                      The Images are loaded in a background Thread . Therefore QImage is used because QPixmaps can only be constructed in Gui Thread.

                      QImage ImageHelper::scaledImageFromImageData(const QByteArray &imageData, const QSize &size, const QRect &source, bool *oIsSvg, QSize *oSize) {
                      //    TraceLine t("scaleLoad");
                          QTransform ot = orientationTransform(imageData);
                          bool isSvg = isSvgImageData(imageData);
                          if (oIsSvg) *oIsSvg = isSvg;
                      
                          QSize scaledSize = size;
                          QRect clipRect = source;
                          if (!ot.isIdentity()) {
                              scaledSize = ot.mapRect(QRect(QPoint(), scaledSize)).size();
                              if (!clipRect.isEmpty()) {
                                  clipRect = QRect();
                      //            QTransform t;
                      //            t.translate(size.width()/2.0,size.height()/2.0);
                      //            t *= ot;
                      //            t.translate(-size.width()/2.0,-size.height()/2.0);
                      //            clipRect = t.mapRect(clipRect);
                              }
                          }
                      
                          QByteArray data = imageData;
                          QBuffer buff(&data);
                          QImageReader reader(&buff);
                          if (!reader.supportsOption(QImageIOHandler::Size)) {
                              qDebug() << "ImageHelper::scaledImageFromImageData() can not determine image original size";
                          }
                          QSize orgSize = reader.size();
                          if(oSize){
                              *oSize = orgSize;
                          }
                          if (!clipRect.isEmpty()) {
                              qreal dx = qreal(orgSize.width())/scaledSize.width();
                              qreal dy = qreal(orgSize.height())/scaledSize.height();
                              QRect clip = QTransform::fromScale(dx, dy).mapRect(QRectF(clipRect)).toAlignedRect();
                              reader.setClipRect(clip);
                              reader.setScaledSize(clipRect.size());
                          } else {
                              reader.setScaledSize(scaledSize);
                          }
                      //    TraceLine *kk = new TraceLine("read");
                          QImage img = reader.read();
                          if(!img.isNull()){
                          //    delete kk;
                              if (!ot.isIdentity()) {
                                  img = img.transformed(ot, Qt::SmoothTransformation);
                                  QSize is = img.size();
                                  if (is != size) {
                                      qDebug() << "transformatino error";
                                  }
                                  if (!source.isEmpty()) {
                                      img = img.copy(source);
                                  }
                              }
                              QSize is = img.size();
                              if (!source.isEmpty()) {
                                  Q_ASSERT(is == source.size());
                              } else {
                                  Q_ASSERT(is == size);
                              }
                          }
                          return img;
                      }
                      

                      The Crash always occurs on the line :

                      QImage img = reader.read();
                      

                      The ByteArray used in this function is loaded via the SqlLite Database Plugin.

                      I really think this is a memory allocating problem. But i don't understand why QWebEngine is in the Stack Trace

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #11

                      @euchkatzl
                      Well, nothing jumps out at me looking at the code.

                      I really think this is a memory allocating problem. But i don't understand why QWebEngine is in the Stack Trace

                      I'd be much more concerned why I don't see QImageReader::read() in the stack trace instead. According to the stack trace (stack trace #1) you're not in ImageHelper::scaledImageFromImageData at all, thus the above code tells us nothing for that case. I'm wary about race conditions (as you could've deduced from my questions), so can you run your code in a single thread and see if it crashes at any of the two places.

                      Kind regards.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        euchkatzl
                        wrote on last edited by
                        #12

                        Thank you.
                        I've done this (run in a single Thread) and voila there is no crash anymore.

                        So i have to limit my Program loading only one tiff at a time on certain platforms (especially on Windows HighDPI because i have to load twice the size there).

                        We have also decided to port the Application to x64, Thank God.
                        There are no crashes anymore, even when loading much tiffs at a time.

                        Thank you all for you help. Topic is now solved for me.

                        1 Reply Last reply
                        1

                        • Login

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