Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. segmentation fault in qt for loop
QtWS25 Last Chance

segmentation fault in qt for loop

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
14 Posts 4 Posters 1.2k 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.
  • S Offline
    S Offline
    swansorter
    wrote on last edited by
    #1

    i have a Qt program which displays the data it receives over UDP.

    this my code...

    int width = 2098, height = 240;
    int bufpo0 = 0, bufpo1 = 1, bufpo2 = 2, bufpo3 = 3;
    QImage img(width, height, QImage::Format_RGB888);
    QByteArray cmd= QByteArray::fromHex(received_data.replace("\r\n","").toLatin1());
    
    
    
       for (int packet = 0; packet < cmd.length(); packet++)//2098*100(lines)=540000packets
       {
    
           Auto_image_RGBdata[packet] = static_cast<quint8>(cmd.data()[bufpo0]) | static_cast<quint8>(cmd.data()[bufpo1]) << 8 | static_cast<quint8>(cmd.data()[bufpo2]) << 16 | static_cast<quint8>(cmd.data()[bufpo3])<< 24;
    
           bufpo0 = bufpo0 + 4;
           bufpo1 = bufpo1 + 4;
           bufpo2 = bufpo2 + 4;
           bufpo3 = bufpo3 + 4;
       }
    
    
    
       for (int y = 0; y < height; y++)
       {
          // for (int x = 0; x < width*3; x+=3)
           for (int x = 0; x < width; x++)
           {
                QRgb value = qRgb((Auto_image_RGBdata[x] >> 22 & 0x000000ff),(Auto_image_RGBdata[x] >> 12 & 0x000000ff), (Auto_image_RGBdata[x]>>2  & 0x000003ff));
               img.setPixel(x,y,value);
           }
       }
        // ui->port->setPixmap(QPixmap::fromImage(img));
        ui->port->setPixmap(QPixmap::fromImage(img.scaled(541,301,Qt::KeepAspectRatio)));
        ui->port->setScaledContents(true);
        // QPixmap::fromImage(img).save("image2.jpg","JPG");
        QPixmap::fromImage(img.scaled(width/4,height*2,Qt::KeepAspectRatio)).save("image2.jpg","JPG");
    
    S JonBJ 2 Replies Last reply
    0
    • S swansorter

      i have a Qt program which displays the data it receives over UDP.

      this my code...

      int width = 2098, height = 240;
      int bufpo0 = 0, bufpo1 = 1, bufpo2 = 2, bufpo3 = 3;
      QImage img(width, height, QImage::Format_RGB888);
      QByteArray cmd= QByteArray::fromHex(received_data.replace("\r\n","").toLatin1());
      
      
      
         for (int packet = 0; packet < cmd.length(); packet++)//2098*100(lines)=540000packets
         {
      
             Auto_image_RGBdata[packet] = static_cast<quint8>(cmd.data()[bufpo0]) | static_cast<quint8>(cmd.data()[bufpo1]) << 8 | static_cast<quint8>(cmd.data()[bufpo2]) << 16 | static_cast<quint8>(cmd.data()[bufpo3])<< 24;
      
             bufpo0 = bufpo0 + 4;
             bufpo1 = bufpo1 + 4;
             bufpo2 = bufpo2 + 4;
             bufpo3 = bufpo3 + 4;
         }
      
      
      
         for (int y = 0; y < height; y++)
         {
            // for (int x = 0; x < width*3; x+=3)
             for (int x = 0; x < width; x++)
             {
                  QRgb value = qRgb((Auto_image_RGBdata[x] >> 22 & 0x000000ff),(Auto_image_RGBdata[x] >> 12 & 0x000000ff), (Auto_image_RGBdata[x]>>2  & 0x000003ff));
                 img.setPixel(x,y,value);
             }
         }
          // ui->port->setPixmap(QPixmap::fromImage(img));
          ui->port->setPixmap(QPixmap::fromImage(img.scaled(541,301,Qt::KeepAspectRatio)));
          ui->port->setScaledContents(true);
          // QPixmap::fromImage(img).save("image2.jpg","JPG");
          QPixmap::fromImage(img.scaled(width/4,height*2,Qt::KeepAspectRatio)).save("image2.jpg","JPG");
      
      S Offline
      S Offline
      swansorter
      wrote on last edited by
      #2

      @swansorter am getting a segmentation fault

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

        Hi,

        What is the stack trace ?

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

        S 2 Replies Last reply
        1
        • S swansorter

          i have a Qt program which displays the data it receives over UDP.

          this my code...

          int width = 2098, height = 240;
          int bufpo0 = 0, bufpo1 = 1, bufpo2 = 2, bufpo3 = 3;
          QImage img(width, height, QImage::Format_RGB888);
          QByteArray cmd= QByteArray::fromHex(received_data.replace("\r\n","").toLatin1());
          
          
          
             for (int packet = 0; packet < cmd.length(); packet++)//2098*100(lines)=540000packets
             {
          
                 Auto_image_RGBdata[packet] = static_cast<quint8>(cmd.data()[bufpo0]) | static_cast<quint8>(cmd.data()[bufpo1]) << 8 | static_cast<quint8>(cmd.data()[bufpo2]) << 16 | static_cast<quint8>(cmd.data()[bufpo3])<< 24;
          
                 bufpo0 = bufpo0 + 4;
                 bufpo1 = bufpo1 + 4;
                 bufpo2 = bufpo2 + 4;
                 bufpo3 = bufpo3 + 4;
             }
          
          
          
             for (int y = 0; y < height; y++)
             {
                // for (int x = 0; x < width*3; x+=3)
                 for (int x = 0; x < width; x++)
                 {
                      QRgb value = qRgb((Auto_image_RGBdata[x] >> 22 & 0x000000ff),(Auto_image_RGBdata[x] >> 12 & 0x000000ff), (Auto_image_RGBdata[x]>>2  & 0x000003ff));
                     img.setPixel(x,y,value);
                 }
             }
              // ui->port->setPixmap(QPixmap::fromImage(img));
              ui->port->setPixmap(QPixmap::fromImage(img.scaled(541,301,Qt::KeepAspectRatio)));
              ui->port->setScaledContents(true);
              // QPixmap::fromImage(img).save("image2.jpg","JPG");
              QPixmap::fromImage(img.scaled(width/4,height*2,Qt::KeepAspectRatio)).save("image2.jpg","JPG");
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @swansorter
          Don't your bufpo? values exceed the length of cmd.data()?

          S 1 Reply Last reply
          1
          • JonBJ JonB

            @swansorter
            Don't your bufpo? values exceed the length of cmd.data()?

            S Offline
            S Offline
            swansorter
            wrote on last edited by
            #5

            @JonB before execeeding only it happens

            JonBJ 1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              What is the stack trace ?

              S Offline
              S Offline
              swansorter
              wrote on last edited by
              #6

              @SGaist
              1.i want to receive 2014080 bytes
              2.Receiving it bunch by bunch
              3.problem is each time i receive data the datagram1(bytearry )updated with new bunch of data and qstring also,so at last i only get last bunch of data.
              4. i tried using global variable qstring it receives all the data but giving (SEGMENTATION FAULT).
              is there any other way to do it .

              this is my udp receive program
              void MainWindow::readPendingDatagrams()
              {
              while(mSocket->hasPendingDatagrams())
              {
              QString received_data_x;
              QByteArray datagram1;
              datagram1.resize(mSocket->pendingDatagramSize());
              mSocket->readDatagram(datagram1.data(),datagram1.size() );
              received_data_x.append(datagram1.toHex());

                 }
              

              }

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                What is the stack trace ?

                S Offline
                S Offline
                swansorter
                wrote on last edited by
                #7

                @SGaist 28621 [1] {
                0x55555562d82c 55 push %rbp
                0x55555562d82d <+0x0001> 48 89 e5 mov %rsp,%rbp
                0x55555562d830 <+0x0004> 53 push %rbx
                0x55555562d831 <+0x0005> 48 81 ec d8 00 00 00 sub $0xd8,%rsp
                0x55555562d838 <+0x000c> 48 89 bd 28 ff ff ff mov %rdi,-0xd8(%rbp)
                0x55555562d83f <+0x0013> 64 48 8b 04 25 28 00 00 00 mov %fs:0x28,%rax
                0x55555562d848 <+0x001c> 48 89 45 e8 mov %rax,-0x18(%rbp)
                0x55555562d84c <+0x0020> 31 c0 xor %eax,%eax
                28635 [1] QString test= x_member;
                0x55555562d84e <+0x0022> 48 8b 85 28 ff ff ff mov -0xd8(%rbp),%rax
                0x55555562d855 <+0x0029> 48 8d 90 88 02 00 00 lea 0x288(%rax),%rdx
                0x55555562d85c <+0x0030> 48 8d 85 68 ff ff ff lea -0x98(%rbp),%rax
                0x55555562d863 <+0x0037> 48 89 d6 mov %rdx,%rsi
                0x55555562d866 <+0x003a> 48 89 c7 mov %rax,%rdi
                0x55555562d869 <+0x003d> e8 26 52 00 00 callq 0x555555632a94 <QString::QString(QString const&)>
                28636 [1] int width = 2098, height = 240;
                0x55555562d86e <+0x0042> c7 85 5c ff ff ff 32 08 00 00 movl $0x832,-0xa4(%rbp)
                0x55555562d878 <+0x004c> c7 85 60 ff ff ff f0 00 00 00 movl $0xf0,-0xa0(%rbp)
                28637 [1] int bufpo0 = 0, bufpo1 = 1, bufpo2 = 2, bufpo3 = 3;
                0x55555562d882 <+0x0056> c7 85 40 ff ff ff 00 00 00 00 movl $0x0,-0xc0(%rbp)
                0x55555562d88c <+0x0060> c7 85 44 ff ff ff 01 00 00 00 movl $0x1,-0xbc(%rbp)
                0x55555562d896 <+0x006a> c7 85 48 ff ff ff 02 00 00 00 movl $0x2,-0xb8(%rbp)
                0x55555562d8a0 <+0x0074> c7 85 4c ff ff ff 03 00 00 00 movl $0x3,-0xb4(%rbp)
                28638 [1] QImage img(width, height, QImage::Format_RGB888);
                0x55555562d8aa <+0x007e> 8b 95 60 ff ff ff mov -0xa0(%rbp),%edx
                0x55555562d8b0 <+0x0084> 8b b5 5c ff ff ff mov -0xa4(%rbp),%esi
                0x55555562d8b6 <+0x008a> 48 8d 45 80 lea -0x80(%rbp),%rax
                0x55555562d8ba <+0x008e> b9 0d 00 00 00 mov $0xd,%ecx
                0x55555562d8bf <+0x0093> 48 89 c7 mov %rax,%rdi
                0x55555562d8c2 <+0x0096> e8 19 f4 f2 ff callq 0x55555555cce0 _ZN6QImageC1EiiNS_6FormatE@plt
                28639 [1] QByteArray cmd= QByteArray::fromHex(test.replace("\r\n","").toLatin1());
                0x55555562d8c7 <+0x009b> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562d8cb <+0x009f> 48 8d 35 06 05 0d 00 lea 0xd0506(%rip),%rsi # 0x5555556fddd8
                0x55555562d8d2 <+0x00a6> 48 89 c7 mov %rax,%rdi
                0x55555562d8d5 <+0x00a9> e8 be 4e 00 00 callq 0x555555632798 <QString::QString(char const*)>
                0x55555562d8da <+0x00ae> 48 8d 85 78 ff ff ff lea -0x88(%rbp),%rax
                0x55555562d8e1 <+0x00b5> 48 8d 35 c8 7e 0d 00 lea 0xd7ec8(%rip),%rsi # 0x5555557057b0
                0x55555562d8e8 <+0x00bc> 48 89 c7 mov %rax,%rdi
                0x55555562d8eb <+0x00bf> e8 a8 4e 00 00 callq 0x555555632798 <QString::QString(char const*)>
                0x55555562d8f0 <+0x00c4> 48 8d 55 a0 lea -0x60(%rbp),%rdx
                0x55555562d8f4 <+0x00c8> 48 8d b5 78 ff ff ff lea -0x88(%rbp),%rsi
                0x55555562d8fb <+0x00cf> 48 8d 85 68 ff ff ff lea -0x98(%rbp),%rax
                0x55555562d902 <+0x00d6> b9 01 00 00 00 mov $0x1,%ecx
                0x55555562d907 <+0x00db> 48 89 c7 mov %rax,%rdi
                0x55555562d90a <+0x00de> e8 b1 fc f2 ff callq 0x55555555d5c0 _ZN7QString7replaceERKS_S1_N2Qt15CaseSensitivityE@plt
                0x55555562d90f <+0x00e3> 48 89 c2 mov %rax,%rdx
                0x55555562d912 <+0x00e6> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562d916 <+0x00ea> 48 89 d6 mov %rdx,%rsi
                0x55555562d919 <+0x00ed> 48 89 c7 mov %rax,%rdi
                0x55555562d91c <+0x00f0> e8 83 4c 00 00 callq 0x5555556325a4 <QString::toLatin1() const &>
                0x55555562d921 <+0x00f5> 48 8d 85 70 ff ff ff lea -0x90(%rbp),%rax
                0x55555562d928 <+0x00fc> 48 8d 55 c0 lea -0x40(%rbp),%rdx
                0x55555562d92c <+0x0100> 48 89 d6 mov %rdx,%rsi
                0x55555562d92f <+0x0103> 48 89 c7 mov %rax,%rdi
                0x55555562d932 <+0x0106> e8 39 f4 f2 ff callq 0x55555555cd70 _ZN10QByteArray7fromHexERKS_@plt
                0x55555562d937 <+0x010b> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562d93b <+0x010f> 48 89 c7 mov %rax,%rdi
                0x55555562d93e <+0x0112> e8 11 00 f3 ff callq 0x55555555d954 QByteArray::~QByteArray()
                0x55555562d943 <+0x0117> 48 8d 85 78 ff ff ff lea -0x88(%rbp),%rax
                0x55555562d94a <+0x011e> 48 89 c7 mov %rax,%rdi
                0x55555562d94d <+0x0121> e8 b8 51 00 00 callq 0x555555632b0a QString::~QString()
                0x55555562d952 <+0x0126> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562d956 <+0x012a> 48 89 c7 mov %rax,%rdi
                0x55555562d959 <+0x012d> e8 ac 51 00 00 callq 0x555555632b0a QString::~QString()
                28643 [1] for (int packet = 0; packet < cmd.length(); packet++)//2098100(lines)=540000packets
                0x55555562d95e <+0x0132> c7 85 50 ff ff ff 00 00 00 00 movl $0x0,-0xb0(%rbp)
                0x55555562d968 <+0x013c> 48 8d 85 70 ff ff ff lea -0x90(%rbp),%rax
                0x55555562d96f <+0x0143> 48 89 c7 mov %rax,%rdi
                0x55555562d972 <+0x0146> e8 71 49 00 00 callq 0x5555556322e8 <QByteArray::length() const>
                0x55555562d977 <+0x014b> 39 85 50 ff ff ff cmp %eax,-0xb0(%rbp)
                0x55555562d97d <+0x0151> 0f 9c c0 setl %al
                0x55555562d980 <+0x0154> 84 c0 test %al,%al
                0x55555562d982 <+0x0156> 0f 84 d8 00 00 00 je 0x55555562da60 MainWindow::on_pushButton_2_pressed()+564
                28648 [1] Auto_image_RGBdata[packet] = static_cast<quint8>(cmd.data()[bufpo0]) | static_cast<quint8>(cmd.data()[bufpo1]) << 8 | static_cast<quint8>(cmd.data()[bufpo2]) << 16 | static_cast<quint8>(cmd.data()[bufpo3])<< 24;
                0x55555562d988 <+0x015c> 48 8d 85 70 ff ff ff lea -0x90(%rbp),%rax
                0x55555562d98f <+0x0163> 48 89 c7 mov %rax,%rdi
                0x55555562d992 <+0x0166> e8 97 49 00 00 callq 0x55555563232e QByteArray::data()
                0x55555562d997 <+0x016b> 48 89 c2 mov %rax,%rdx
                0x55555562d99a <+0x016e> 8b 85 40 ff ff ff mov -0xc0(%rbp),%eax
                0x55555562d9a0 <+0x0174> 48 98 cltq
                0x55555562d9a2 <+0x0176> 48 01 d0 add %rdx,%rax
                0x55555562d9a5 <+0x0179> 0f b6 00 movzbl (%rax),%eax
                0x55555562d9a8 <+0x017c> 0f b6 d8 movzbl %al,%ebx
                0x55555562d9ab <+0x017f> 48 8d 85 70 ff ff ff lea -0x90(%rbp),%rax
                0x55555562d9b2 <+0x0186> 48 89 c7 mov %rax,%rdi
                0x55555562d9b5 <+0x0189> e8 74 49 00 00 callq 0x55555563232e QByteArray::data()
                0x55555562d9ba <+0x018e> 48 89 c2 mov %rax,%rdx
                0x55555562d9bd <+0x0191> 8b 85 44 ff ff ff mov -0xbc(%rbp),%eax
                0x55555562d9c3 <+0x0197> 48 98 cltq
                0x55555562d9c5 <+0x0199> 48 01 d0 add %rdx,%rax
                0x55555562d9c8 <+0x019c> 0f b6 00 movzbl (%rax),%eax
                0x55555562d9cb <+0x019f> 0f b6 c0 movzbl %al,%eax
                0x55555562d9ce <+0x01a2> c1 e0 08 shl $0x8,%eax
                0x55555562d9d1 <+0x01a5> 09 c3 or %eax,%ebx
                0x55555562d9d3 <+0x01a7> 48 8d 85 70 ff ff ff lea -0x90(%rbp),%rax
                0x55555562d9da <+0x01ae> 48 89 c7 mov %rax,%rdi
                0x55555562d9dd <+0x01b1> e8 4c 49 00 00 callq 0x55555563232e QByteArray::data()
                0x55555562d9e2 <+0x01b6> 48 89 c2 mov %rax,%rdx
                0x55555562d9e5 <+0x01b9> 8b 85 48 ff ff ff mov -0xb8(%rbp),%eax
                0x55555562d9eb <+0x01bf> 48 98 cltq
                0x55555562d9ed <+0x01c1> 48 01 d0 add %rdx,%rax
                0x55555562d9f0 <+0x01c4> 0f b6 00 movzbl (%rax),%eax
                0x55555562d9f3 <+0x01c7> 0f b6 c0 movzbl %al,%eax
                0x55555562d9f6 <+0x01ca> c1 e0 10 shl $0x10,%eax
                0x55555562d9f9 <+0x01cd> 09 c3 or %eax,%ebx
                0x55555562d9fb <+0x01cf> 48 8d 85 70 ff ff ff lea -0x90(%rbp),%rax
                0x55555562da02 <+0x01d6> 48 89 c7 mov %rax,%rdi
                0x55555562da05 <+0x01d9> e8 24 49 00 00 callq 0x55555563232e QByteArray::data()
                0x55555562da0a <+0x01de> 48 89 c2 mov %rax,%rdx
                0x55555562da0d <+0x01e1> 8b 85 4c ff ff ff mov -0xb4(%rbp),%eax
                0x55555562da13 <+0x01e7> 48 98 cltq
                0x55555562da15 <+0x01e9> 48 01 d0 add %rdx,%rax
                0x55555562da18 <+0x01ec> 0f b6 00 movzbl (%rax),%eax
                0x55555562da1b <+0x01ef> 0f b6 c0 movzbl %al,%eax
                0x55555562da1e <+0x01f2> c1 e0 18 shl $0x18,%eax
                0x55555562da21 <+0x01f5> 89 d9 mov %ebx,%ecx
                0x55555562da23 <+0x01f7> 09 c1 or %eax,%ecx
                0x55555562da25 <+0x01f9> 48 8d 05 74 a5 3a 00 lea 0x3aa574(%rip),%rax # 0x5555559d7fa0 <Auto_image_RGBdata>
                0x55555562da2c <+0x0200> 8b 95 50 ff ff ff mov -0xb0(%rbp),%edx
                0x55555562da32 <+0x0206> 48 63 d2 movslq %edx,%rdx
                0x55555562da35 <+0x0209> 89 0c 90 mov %ecx,(%rax,%rdx,4)
                28658 [1] bufpo0 = bufpo0 + 4;
                0x55555562da38 <+0x020c> 83 85 40 ff ff ff 04 addl $0x4,-0xc0(%rbp)
                28659 [1] bufpo1 = bufpo1 + 4;
                0x55555562da3f <+0x0213> 83 85 44 ff ff ff 04 addl $0x4,-0xbc(%rbp)
                28660 [1] bufpo2 = bufpo2 + 4;
                0x55555562da46 <+0x021a> 83 85 48 ff ff ff 04 addl $0x4,-0xb8(%rbp)
                28661 [1] bufpo3 = bufpo3 + 4;
                0x55555562da4d <+0x0221> 83 85 4c ff ff ff 04 addl $0x4,-0xb4(%rbp)
                28643 [2] for (int packet = 0; packet < cmd.length(); packet++)//2098
                100(lines)=540000packets
                0x55555562da54 <+0x0228> 83 85 50 ff ff ff 01 addl $0x1,-0xb0(%rbp)
                0x55555562da5b <+0x022f> e9 08 ff ff ff jmpq 0x55555562d968 MainWindow::on_pushButton_2_pressed()+316
                28666 [1] for (int y = 0; y < height; y++)
                0x55555562da60 <+0x0234> c7 85 54 ff ff ff 00 00 00 00 movl $0x0,-0xac(%rbp)
                0x55555562da6a <+0x023e> 8b 85 54 ff ff ff mov -0xac(%rbp),%eax
                0x55555562da70 <+0x0244> 3b 85 60 ff ff ff cmp -0xa0(%rbp),%eax
                0x55555562da76 <+0x024a> 0f 8d b2 00 00 00 jge 0x55555562db2e MainWindow::on_pushButton_2_pressed()+770
                28669 [1] for (int x = 0; x < width; x++)
                0x55555562da7c <+0x0250> c7 85 58 ff ff ff 00 00 00 00 movl $0x0,-0xa8(%rbp)
                0x55555562da86 <+0x025a> 8b 85 58 ff ff ff mov -0xa8(%rbp),%eax
                0x55555562da8c <+0x0260> 3b 85 5c ff ff ff cmp -0xa4(%rbp),%eax
                0x55555562da92 <+0x0266> 0f 8d 8a 00 00 00 jge 0x55555562db22 MainWindow::on_pushButton_2_pressed()+758

                >> 22 & 0x000000ff),(Auto_image_RGBdata[x] >> 12 & 0x000000ff), (Auto_image_RGBdata[x]>>2 & 0x000003ff));

                0x55555562da98 <+0x026c> 48 8d 05 01 a5 3a 00 lea 0x3aa501(%rip),%rax # 0x5555559d7fa0 <Auto_image_RGBdata>
                0x55555562da9f <+0x0273> 8b 95 58 ff ff ff mov -0xa8(%rbp),%edx
                0x55555562daa5 <+0x0279> 48 63 d2 movslq %edx,%rdx
                0x55555562daa8 <+0x027c> 8b 04 90 mov (%rax,%rdx,4),%eax
                0x55555562daab <+0x027f> c1 f8 02 sar $0x2,%eax
                0x55555562daae <+0x0282> 25 ff 03 00 00 and $0x3ff,%eax
                0x55555562dab3 <+0x0287> 89 c6 mov %eax,%esi
                0x55555562dab5 <+0x0289> 48 8d 05 e4 a4 3a 00 lea 0x3aa4e4(%rip),%rax # 0x5555559d7fa0 <Auto_image_RGBdata>
                0x55555562dabc <+0x0290> 8b 95 58 ff ff ff mov -0xa8(%rbp),%edx
                0x55555562dac2 <+0x0296> 48 63 d2 movslq %edx,%rdx
                0x55555562dac5 <+0x0299> 8b 04 90 mov (%rax,%rdx,4),%eax
                0x55555562dac8 <+0x029c> c1 f8 0c sar $0xc,%eax
                0x55555562dacb <+0x029f> 0f b6 c8 movzbl %al,%ecx
                0x55555562dace <+0x02a2> 48 8d 05 cb a4 3a 00 lea 0x3aa4cb(%rip),%rax # 0x5555559d7fa0 <Auto_image_RGBdata>
                0x55555562dad5 <+0x02a9> 8b 95 58 ff ff ff mov -0xa8(%rbp),%edx
                0x55555562dadb <+0x02af> 48 63 d2 movslq %edx,%rdx
                0x55555562dade <+0x02b2> 8b 04 90 mov (%rax,%rdx,4),%eax
                0x55555562dae1 <+0x02b5> c1 f8 16 sar $0x16,%eax
                0x55555562dae4 <+0x02b8> 0f b6 c0 movzbl %al,%eax
                0x55555562dae7 <+0x02bb> 89 f2 mov %esi,%edx
                0x55555562dae9 <+0x02bd> 89 ce mov %ecx,%esi
                0x55555562daeb <+0x02bf> 89 c7 mov %eax,%edi
                0x55555562daed <+0x02c1> e8 ff 56 00 00 callq 0x5555556331f1 <qRgb(int, int, int)>
                0x55555562daf2 <+0x02c6> 89 85 64 ff ff ff mov %eax,-0x9c(%rbp)
                28672 [1] img.setPixel(x,y,value);
                0x55555562daf8 <+0x02cc> 8b 8d 64 ff ff ff mov -0x9c(%rbp),%ecx
                0x55555562dafe <+0x02d2> 8b 95 54 ff ff ff mov -0xac(%rbp),%edx
                0x55555562db04 <+0x02d8> 8b b5 58 ff ff ff mov -0xa8(%rbp),%esi
                0x55555562db0a <+0x02de> 48 8d 45 80 lea -0x80(%rbp),%rax
                0x55555562db0e <+0x02e2> 48 89 c7 mov %rax,%rdi
                0x55555562db11 <+0x02e5> e8 aa f0 f2 ff callq 0x55555555cbc0 _ZN6QImage8setPixelEiij@plt
                28669 [2] for (int x = 0; x < width; x++)
                0x55555562db16 <+0x02ea> 83 85 58 ff ff ff 01 addl $0x1,-0xa8(%rbp)
                0x55555562db1d <+0x02f1> e9 64 ff ff ff jmpq 0x55555562da86 MainWindow::on_pushButton_2_pressed()+602
                28666 [2] for (int y = 0; y < height; y++)
                0x55555562db22 <+0x02f6> 83 85 54 ff ff ff 01 addl $0x1,-0xac(%rbp)
                0x55555562db29 <+0x02fd> e9 3c ff ff ff jmpq 0x55555562da6a MainWindow::on_pushButton_2_pressed()+574
                28676 [1] ui->port->setPixmap(QPixmap::fromImage(img.scaled(541,301,Qt::KeepAspectRatio)));
                0x55555562db2e <+0x0302> 48 8b 85 28 ff ff ff mov -0xd8(%rbp),%rax
                0x55555562db35 <+0x0309> 48 8b 80 20 02 00 00 mov 0x220(%rax),%rax
                0x55555562db3c <+0x0310> 48 8b 98 90 00 00 00 mov 0x90(%rax),%rbx
                0x55555562db43 <+0x0317> 48 8d 85 78 ff ff ff lea -0x88(%rbp),%rax
                0x55555562db4a <+0x031e> be 00 00 00 00 mov $0x0,%esi
                0x55555562db4f <+0x0323> 48 89 c7 mov %rax,%rdi
                0x55555562db52 <+0x0326> e8 8d 44 00 00 callq 0x555555631fe4 <QFlagsQt::ImageConversionFlag::QFlags(Qt::ImageConversionFlag)>
                0x55555562db57 <+0x032b> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562db5b <+0x032f> 48 8d 75 80 lea -0x80(%rbp),%rsi
                0x55555562db5f <+0x0333> 41 b9 00 00 00 00 mov $0x0,%r9d
                0x55555562db65 <+0x0339> 41 b8 01 00 00 00 mov $0x1,%r8d
                0x55555562db6b <+0x033f> b9 2d 01 00 00 mov $0x12d,%ecx
                0x55555562db70 <+0x0344> ba 1d 02 00 00 mov $0x21d,%edx
                0x55555562db75 <+0x0349> 48 89 c7 mov %rax,%rdi
                0x55555562db78 <+0x034c> e8 9d 57 00 00 callq 0x55555563331a <QImage::scaled(int, int, Qt::AspectRatioMode, Qt::TransformationMode) const>
                0x55555562db7d <+0x0351> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562db81 <+0x0355> 8b 95 78 ff ff ff mov -0x88(%rbp),%edx
                0x55555562db87 <+0x035b> 48 8d 4d a0 lea -0x60(%rbp),%rcx
                0x55555562db8b <+0x035f> 48 89 ce mov %rcx,%rsi
                0x55555562db8e <+0x0362> 48 89 c7 mov %rax,%rdi
                0x55555562db91 <+0x0365> e8 fc 57 00 00 callq 0x555555633392 <QPixmap::fromImage(QImage&&, QFlagsQt::ImageConversionFlag)>
                0x55555562db96 <+0x036a> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562db9a <+0x036e> 48 89 c6 mov %rax,%rsi
                0x55555562db9d <+0x0371> 48 89 df mov %rbx,%rdi
                0x55555562dba0 <+0x0374> e8 6b f3 f2 ff callq 0x55555555cf10 _ZN6QLabel9setPixmapERK7QPixmap@plt
                0x55555562dba5 <+0x0379> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562dba9 <+0x037d> 48 89 c7 mov %rax,%rdi
                0x55555562dbac <+0x0380> e8 3f ec f2 ff callq 0x55555555c7f0 _ZN7QPixmapD1Ev@plt
                0x55555562dbb1 <+0x0385> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562dbb5 <+0x0389> 48 89 c7 mov %rax,%rdi
                0x55555562dbb8 <+0x038c> e8 33 f1 f2 ff callq 0x55555555ccf0 _ZN6QImageD1Ev@plt
                28677 [1] ui->port->setScaledContents(true);
                0x55555562dbbd <+0x0391> 48 8b 85 28 ff ff ff mov -0xd8(%rbp),%rax
                0x55555562dbc4 <+0x0398> 48 8b 80 20 02 00 00 mov 0x220(%rax),%rax
                0x55555562dbcb <+0x039f> 48 8b 80 90 00 00 00 mov 0x90(%rax),%rax
                0x55555562dbd2 <+0x03a6> be 01 00 00 00 mov $0x1,%esi
                0x55555562dbd7 <+0x03ab> 48 89 c7 mov %rax,%rdi
                0x55555562dbda <+0x03ae> e8 41 f1 f2 ff callq 0x55555555cd20 _ZN6QLabel17setScaledContentsEb@plt
                28679 [1] QPixmap::fromImage(img.scaled(width/4,height2,Qt::KeepAspectRatio)).save("image2.jpg","JPG");
                0x55555562dbdf <+0x03b3> 48 8d 85 3c ff ff ff lea -0xc4(%rbp),%rax
                0x55555562dbe6 <+0x03ba> be 00 00 00 00 mov $0x0,%esi
                0x55555562dbeb <+0x03bf> 48 89 c7 mov %rax,%rdi
                0x55555562dbee <+0x03c2> e8 f1 43 00 00 callq 0x555555631fe4 <QFlagsQt::ImageConversionFlag::QFlags(Qt::ImageConversionFlag)>
                0x55555562dbf3 <+0x03c7> 8b 85 60 ff ff ff mov -0xa0(%rbp),%eax
                0x55555562dbf9 <+0x03cd> 8d 14 00 lea (%rax,%rax,1),%edx
                0x55555562dbfc <+0x03d0> 8b 85 5c ff ff ff mov -0xa4(%rbp),%eax
                0x55555562dc02 <+0x03d6> 8d 48 03 lea 0x3(%rax),%ecx
                0x55555562dc05 <+0x03d9> 85 c0 test %eax,%eax
                0x55555562dc07 <+0x03db> 0f 48 c1 cmovs %ecx,%eax
                0x55555562dc0a <+0x03de> c1 f8 02 sar $0x2,%eax
                0x55555562dc0d <+0x03e1> 89 c7 mov %eax,%edi
                0x55555562dc0f <+0x03e3> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562dc13 <+0x03e7> 48 8d 75 80 lea -0x80(%rbp),%rsi
                0x55555562dc17 <+0x03eb> 41 b9 00 00 00 00 mov $0x0,%r9d
                0x55555562dc1d <+0x03f1> 41 b8 01 00 00 00 mov $0x1,%r8d
                0x55555562dc23 <+0x03f7> 89 d1 mov %edx,%ecx
                0x55555562dc25 <+0x03f9> 89 fa mov %edi,%edx
                0x55555562dc27 <+0x03fb> 48 89 c7 mov %rax,%rdi
                0x55555562dc2a <+0x03fe> e8 eb 56 00 00 callq 0x55555563331a <QImage::scaled(int, int, Qt::AspectRatioMode, Qt::TransformationMode) const>
                0x55555562dc2f <+0x0403> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562dc33 <+0x0407> 8b 95 3c ff ff ff mov -0xc4(%rbp),%edx
                0x55555562dc39 <+0x040d> 48 8d 4d a0 lea -0x60(%rbp),%rcx
                0x55555562dc3d <+0x0411> 48 89 ce mov %rcx,%rsi
                0x55555562dc40 <+0x0414> 48 89 c7 mov %rax,%rdi
                0x55555562dc43 <+0x0417> e8 4a 57 00 00 callq 0x555555633392 <QPixmap::fromImage(QImage&&, QFlagsQt::ImageConversionFlag)>
                0x55555562dc48 <+0x041c> 48 8d 85 78 ff ff ff lea -0x88(%rbp),%rax
                0x55555562dc4f <+0x0423> 48 8d 35 5d 7b 0d 00 lea 0xd7b5d(%rip),%rsi # 0x5555557057b3
                0x55555562dc56 <+0x042a> 48 89 c7 mov %rax,%rdi
                0x55555562dc59 <+0x042d> e8 3a 4b 00 00 callq 0x555555632798 <QString::QString(char const
                )>
                0x55555562dc5e <+0x0432> 48 8d b5 78 ff ff ff lea -0x88(%rbp),%rsi
                0x55555562dc65 <+0x0439> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562dc69 <+0x043d> b9 ff ff ff ff mov $0xffffffff,%ecx
                0x55555562dc6e <+0x0442> 48 8d 15 49 7b 0d 00 lea 0xd7b49(%rip),%rdx # 0x5555557057be
                0x55555562dc75 <+0x0449> 48 89 c7 mov %rax,%rdi
                0x55555562dc78 <+0x044c> e8 43 f6 f2 ff callq 0x55555555d2c0 _ZNK7QPixmap4saveERK7QStringPKci@plt
                0x55555562dc7d <+0x0451> 48 8d 85 78 ff ff ff lea -0x88(%rbp),%rax
                0x55555562dc84 <+0x0458> 48 89 c7 mov %rax,%rdi
                0x55555562dc87 <+0x045b> e8 7e 4e 00 00 callq 0x555555632b0a QString::~QString()
                0x55555562dc8c <+0x0460> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562dc90 <+0x0464> 48 89 c7 mov %rax,%rdi
                0x55555562dc93 <+0x0467> e8 58 eb f2 ff callq 0x55555555c7f0 _ZN7QPixmapD1Ev@plt
                0x55555562dc98 <+0x046c> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562dc9c <+0x0470> 48 89 c7 mov %rax,%rdi
                0x55555562dc9f <+0x0473> e8 4c f0 f2 ff callq 0x55555555ccf0 _ZN6QImageD1Ev@plt
                28639 [2] QByteArray cmd= QByteArray::fromHex(test.replace("\r\n","").toLatin1());
                0x55555562dca4 <+0x0478> 48 8d 85 70 ff ff ff lea -0x90(%rbp),%rax
                0x55555562dcab <+0x047f> 48 89 c7 mov %rax,%rdi
                0x55555562dcae <+0x0482> e8 a1 fc f2 ff callq 0x55555555d954 QByteArray::~QByteArray()
                28638 [2] QImage img(width, height, QImage::Format_RGB888);
                0x55555562dcb3 <+0x0487> 48 8d 45 80 lea -0x80(%rbp),%rax
                0x55555562dcb7 <+0x048b> 48 89 c7 mov %rax,%rdi
                0x55555562dcba <+0x048e> e8 31 f0 f2 ff callq 0x55555555ccf0 _ZN6QImageD1Ev@plt
                28635 [2] QString test= x_member;
                0x55555562dcbf <+0x0493> 48 8d 85 68 ff ff ff lea -0x98(%rbp),%rax
                0x55555562dcc6 <+0x049a> 48 89 c7 mov %rax,%rdi
                0x55555562dcc9 <+0x049d> e8 3c 4e 00 00 callq 0x555555632b0a QString::~QString()
                28683 [1] }
                0x55555562dcce <+0x04a2> 90 nop
                0x55555562dccf <+0x04a3> 48 8b 45 e8 mov -0x18(%rbp),%rax
                0x55555562dcd3 <+0x04a7> 64 48 33 04 25 28 00 00 00 xor %fs:0x28,%rax
                0x55555562dcdc <+0x04b0> 0f 84 da 00 00 00 je 0x55555562ddbc MainWindow::on_pushButton_2_pressed()+1424
                0x55555562dce2 <+0x04b6> e9 d0 00 00 00 jmpq 0x55555562ddb7 MainWindow::on_pushButton_2_pressed()+1419
                0x55555562dce7 <+0x04bb> 48 89 c3 mov %rax,%rbx
                0x55555562dcea <+0x04be> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562dcee <+0x04c2> 48 89 c7 mov %rax,%rdi
                0x55555562dcf1 <+0x04c5> e8 5e fc f2 ff callq 0x55555555d954 QByteArray::~QByteArray()
                0x55555562dcf6 <+0x04ca> eb 03 jmp 0x55555562dcfb MainWindow::on_pushButton_2_pressed()+1231
                0x55555562dcf8 <+0x04cc> 48 89 c3 mov %rax,%rbx
                0x55555562dcfb <+0x04cf> 48 8d 85 78 ff ff ff lea -0x88(%rbp),%rax
                0x55555562dd02 <+0x04d6> 48 89 c7 mov %rax,%rdi
                0x55555562dd05 <+0x04d9> e8 00 4e 00 00 callq 0x555555632b0a QString::~QString()
                0x55555562dd0a <+0x04de> eb 03 jmp 0x55555562dd0f MainWindow::on_pushButton_2_pressed()+1251
                0x55555562dd0c <+0x04e0> 48 89 c3 mov %rax,%rbx
                0x55555562dd0f <+0x04e3> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562dd13 <+0x04e7> 48 89 c7 mov %rax,%rdi
                0x55555562dd16 <+0x04ea> e8 ef 4d 00 00 callq 0x555555632b0a QString::~QString()
                0x55555562dd1b <+0x04ef> eb 6f jmp 0x55555562dd8c MainWindow::on_pushButton_2_pressed()+1376
                0x55555562dd1d <+0x04f1> 48 89 c3 mov %rax,%rbx
                28676 [2] ui->port->setPixmap(QPixmap::fromImage(img.scaled(541,301,Qt::KeepAspectRatio)));
                0x55555562dd20 <+0x04f4> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562dd24 <+0x04f8> 48 89 c7 mov %rax,%rdi
                0x55555562dd27 <+0x04fb> e8 c4 ea f2 ff callq 0x55555555c7f0 _ZN7QPixmapD1Ev@plt
                0x55555562dd2c <+0x0500> eb 03 jmp 0x55555562dd31 MainWindow::on_pushButton_2_pressed()+1285
                0x55555562dd2e <+0x0502> 48 89 c3 mov %rax,%rbx
                0x55555562dd31 <+0x0505> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562dd35 <+0x0509> 48 89 c7 mov %rax,%rdi
                0x55555562dd38 <+0x050c> e8 b3 ef f2 ff callq 0x55555555ccf0 _ZN6QImageD1Ev@plt
                0x55555562dd3d <+0x0511> eb 39 jmp 0x55555562dd78 MainWindow::on_pushButton_2_pressed()+1356
                0x55555562dd3f <+0x0513> 48 89 c3 mov %rax,%rbx
                28679 [2] QPixmap::fromImage(img.scaled(width/4,height*2,Qt::KeepAspectRatio)).save("image2.jpg","JPG");
                0x55555562dd42 <+0x0516> 48 8d 85 78 ff ff ff lea -0x88(%rbp),%rax
                0x55555562dd49 <+0x051d> 48 89 c7 mov %rax,%rdi
                0x55555562dd4c <+0x0520> e8 b9 4d 00 00 callq 0x555555632b0a QString::~QString()
                0x55555562dd51 <+0x0525> eb 03 jmp 0x55555562dd56 MainWindow::on_pushButton_2_pressed()+1322
                0x55555562dd53 <+0x0527> 48 89 c3 mov %rax,%rbx
                0x55555562dd56 <+0x052a> 48 8d 45 c0 lea -0x40(%rbp),%rax
                0x55555562dd5a <+0x052e> 48 89 c7 mov %rax,%rdi
                0x55555562dd5d <+0x0531> e8 8e ea f2 ff callq 0x55555555c7f0 _ZN7QPixmapD1Ev@plt
                0x55555562dd62 <+0x0536> eb 03 jmp 0x55555562dd67 MainWindow::on_pushButton_2_pressed()+1339
                0x55555562dd64 <+0x0538> 48 89 c3 mov %rax,%rbx
                0x55555562dd67 <+0x053b> 48 8d 45 a0 lea -0x60(%rbp),%rax
                0x55555562dd6b <+0x053f> 48 89 c7 mov %rax,%rdi
                0x55555562dd6e <+0x0542> e8 7d ef f2 ff callq 0x55555555ccf0 _ZN6QImageD1Ev@plt
                0x55555562dd73 <+0x0547> eb 03 jmp 0x55555562dd78 MainWindow::on_pushButton_2_pressed()+1356
                0x55555562dd75 <+0x0549> 48 89 c3 mov %rax,%rbx
                28639 [3] QByteArray cmd= QByteArray::fromHex(test.replace("\r\n","").toLatin1());
                0x55555562dd78 <+0x054c> 48 8d 85 70 ff ff ff lea -0x90(%rbp),%rax
                0x55555562dd7f <+0x0553> 48 89 c7 mov %rax,%rdi
                0x55555562dd82 <+0x0556> e8 cd fb f2 ff callq 0x55555555d954 QByteArray::~QByteArray()
                0x55555562dd87 <+0x055b> eb 03 jmp 0x55555562dd8c MainWindow::on_pushButton_2_pressed()+1376
                0x55555562dd89 <+0x055d> 48 89 c3 mov %rax,%rbx
                28638 [3] QImage img(width, height, QImage::Format_RGB888);
                0x55555562dd8c <+0x0560> 48 8d 45 80 lea -0x80(%rbp),%rax
                0x55555562dd90 <+0x0564> 48 89 c7 mov %rax,%rdi
                0x55555562dd93 <+0x0567> e8 58 ef f2 ff callq 0x55555555ccf0 _ZN6QImageD1Ev@plt
                0x55555562dd98 <+0x056c> eb 03 jmp 0x55555562dd9d MainWindow::on_pushButton_2_pressed()+1393
                0x55555562dd9a <+0x056e> 48 89 c3 mov %rax,%rbx
                28635 [3] QString test= x_member;
                0x55555562dd9d <+0x0571> 48 8d 85 68 ff ff ff lea -0x98(%rbp),%rax
                0x55555562dda4 <+0x0578> 48 89 c7 mov %rax,%rdi
                0x55555562dda7 <+0x057b> e8 5e 4d 00 00 callq 0x555555632b0a QString::~QString()
                0x55555562ddac <+0x0580> 48 89 d8 mov %rbx,%rax
                0x55555562ddaf <+0x0583> 48 89 c7 mov %rax,%rdi
                0x55555562ddb2 <+0x0586> e8 39 ee f2 ff callq 0x55555555cbf0 _Unwind_Resume@plt
                28683 [2] }
                0x55555562ddb7 <+0x058b> e8 14 ec f2 ff callq 0x55555555c9d0 __stack_chk_fail@plt
                0x55555562ddbc <+0x0590> 48 81 c4 d8 00 00 00 add $0xd8,%rsp
                0x55555562ddc3 <+0x0597> 5b pop %rbx
                0x55555562ddc4 <+0x0598> 5d pop %rbp
                0x55555562ddc5 <+0x0599> c3 retq

                1 Reply Last reply
                0
                • S swansorter

                  @JonB before execeeding only it happens

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @swansorter said in segmentation fault in qt for loop:

                  @JonB before execeeding only it happens

                  I don't know what you mean by this, According to my analysis, you will exceed reading from the end of the cmd array just as you reach one quarter of the way through your for loop. Don't you think you need to address that with a correct algorithm?

                  Meanwhile, when you do crash while running it inside the debugger, @SGaist has asked you to do so and show the stack trace window, which is the call stack leading back to the exact line in your code which is the cause. What you have shown is a disassembly window, which is not what we are asking to see.

                  Furthermore, I now see you are pursuing the same question with the same code in thread https://forum.qt.io/topic/118812/receive-data-with-udp-protocol. Please do not do this, it;s not fair on those who spend time trying to answer your questions.

                  And I also see there you are saying the seg fault happens in the for loop I am talking about, which makes it all the more pressing for you to address the issue of its bounds where I have said your code is incorrect....

                  Meanwhile, since you assign to Auto_image_RGBdata[packet] = ..., show the declaration/size of that array. If it's less than cmd.length() you will be poking into unallocated memory, and that may cause a seg fault....

                  I strongly suspect that the code in your loop is not doing what you are intending it to do.

                  S 3 Replies Last reply
                  0
                  • JonBJ JonB

                    @swansorter said in segmentation fault in qt for loop:

                    @JonB before execeeding only it happens

                    I don't know what you mean by this, According to my analysis, you will exceed reading from the end of the cmd array just as you reach one quarter of the way through your for loop. Don't you think you need to address that with a correct algorithm?

                    Meanwhile, when you do crash while running it inside the debugger, @SGaist has asked you to do so and show the stack trace window, which is the call stack leading back to the exact line in your code which is the cause. What you have shown is a disassembly window, which is not what we are asking to see.

                    Furthermore, I now see you are pursuing the same question with the same code in thread https://forum.qt.io/topic/118812/receive-data-with-udp-protocol. Please do not do this, it;s not fair on those who spend time trying to answer your questions.

                    And I also see there you are saying the seg fault happens in the for loop I am talking about, which makes it all the more pressing for you to address the issue of its bounds where I have said your code is incorrect....

                    Meanwhile, since you assign to Auto_image_RGBdata[packet] = ..., show the declaration/size of that array. If it's less than cmd.length() you will be poking into unallocated memory, and that may cause a seg fault....

                    I strongly suspect that the code in your loop is not doing what you are intending it to do.

                    S Offline
                    S Offline
                    swansorter
                    wrote on last edited by
                    #9

                    @JonB Screenshot from 2020-09-10 15-42-57.png

                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @swansorter said in segmentation fault in qt for loop:

                      @JonB before execeeding only it happens

                      I don't know what you mean by this, According to my analysis, you will exceed reading from the end of the cmd array just as you reach one quarter of the way through your for loop. Don't you think you need to address that with a correct algorithm?

                      Meanwhile, when you do crash while running it inside the debugger, @SGaist has asked you to do so and show the stack trace window, which is the call stack leading back to the exact line in your code which is the cause. What you have shown is a disassembly window, which is not what we are asking to see.

                      Furthermore, I now see you are pursuing the same question with the same code in thread https://forum.qt.io/topic/118812/receive-data-with-udp-protocol. Please do not do this, it;s not fair on those who spend time trying to answer your questions.

                      And I also see there you are saying the seg fault happens in the for loop I am talking about, which makes it all the more pressing for you to address the issue of its bounds where I have said your code is incorrect....

                      Meanwhile, since you assign to Auto_image_RGBdata[packet] = ..., show the declaration/size of that array. If it's less than cmd.length() you will be poking into unallocated memory, and that may cause a seg fault....

                      I strongly suspect that the code in your loop is not doing what you are intending it to do.

                      S Offline
                      S Offline
                      swansorter
                      wrote on last edited by
                      #10

                      @JonB
                      qint32Auto_image_RGBdata[2014080] ={0}

                      .

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @swansorter said in segmentation fault in qt for loop:

                        @JonB before execeeding only it happens

                        I don't know what you mean by this, According to my analysis, you will exceed reading from the end of the cmd array just as you reach one quarter of the way through your for loop. Don't you think you need to address that with a correct algorithm?

                        Meanwhile, when you do crash while running it inside the debugger, @SGaist has asked you to do so and show the stack trace window, which is the call stack leading back to the exact line in your code which is the cause. What you have shown is a disassembly window, which is not what we are asking to see.

                        Furthermore, I now see you are pursuing the same question with the same code in thread https://forum.qt.io/topic/118812/receive-data-with-udp-protocol. Please do not do this, it;s not fair on those who spend time trying to answer your questions.

                        And I also see there you are saying the seg fault happens in the for loop I am talking about, which makes it all the more pressing for you to address the issue of its bounds where I have said your code is incorrect....

                        Meanwhile, since you assign to Auto_image_RGBdata[packet] = ..., show the declaration/size of that array. If it's less than cmd.length() you will be poking into unallocated memory, and that may cause a seg fault....

                        I strongly suspect that the code in your loop is not doing what you are intending it to do.

                        S Offline
                        S Offline
                        swansorter
                        wrote on last edited by
                        #11

                        @JonB
                        for loop changed

                                            for ( int packet = 0; packet < 2014080; packet++)
                                              {
                                                 Auto_image_RGBdata[packet] = static_cast<quint8>(cmd.data()[bufpo0]) | static_cast<quint8>(cmd.data()[bufpo1]) << 8 | static_cast<quint8>(cmd.data()[bufpo2]) << 16 | static_cast<quint8>(cmd.data()[bufpo3])<< 24;
                                                  bufpo0 = bufpo0 + 4;
                                                  bufpo1 = bufpo1 + 4;
                                                  bufpo2 = bufpo2 + 4;
                                                  bufpo3 = bufpo3 + 4;
                                              }
                        
                        KroMignonK 1 Reply Last reply
                        0
                        • S swansorter

                          @JonB
                          for loop changed

                                              for ( int packet = 0; packet < 2014080; packet++)
                                                {
                                                   Auto_image_RGBdata[packet] = static_cast<quint8>(cmd.data()[bufpo0]) | static_cast<quint8>(cmd.data()[bufpo1]) << 8 | static_cast<quint8>(cmd.data()[bufpo2]) << 16 | static_cast<quint8>(cmd.data()[bufpo3])<< 24;
                                                    bufpo0 = bufpo0 + 4;
                                                    bufpo1 = bufpo1 + 4;
                                                    bufpo2 = bufpo2 + 4;
                                                    bufpo3 = bufpo3 + 4;
                                                }
                          
                          KroMignonK Offline
                          KroMignonK Offline
                          KroMignon
                          wrote on last edited by KroMignon
                          #12

                          @swansorter said in segmentation fault in qt for loop:

                          for loop changed

                          Auto_image_RGBdata[packet] = static_cast<quint8>(cmd.data()[bufpo0]) | static_cast<quint8>(cmd.data()[bufpo1]) << 8 | static_cast<quint8>(cmd.data()[bufpo2]) << 16 | static_cast<quint8>(cmd.data()[bufpo3])<< 24;
                          

                          Are you sure bufpo0 < cmd.size() and bufpo1 < cmd.size() and bufpo2 < cmd.size() and bufpo3 < cmd.size()?

                          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                          S 1 Reply Last reply
                          2
                          • KroMignonK KroMignon

                            @swansorter said in segmentation fault in qt for loop:

                            for loop changed

                            Auto_image_RGBdata[packet] = static_cast<quint8>(cmd.data()[bufpo0]) | static_cast<quint8>(cmd.data()[bufpo1]) << 8 | static_cast<quint8>(cmd.data()[bufpo2]) << 16 | static_cast<quint8>(cmd.data()[bufpo3])<< 24;
                            

                            Are you sure bufpo0 < cmd.size() and bufpo1 < cmd.size() and bufpo2 < cmd.size() and bufpo3 < cmd.size()?

                            S Offline
                            S Offline
                            swansorter
                            wrote on last edited by
                            #13

                            @KroMignon problem solved thank you

                            JonBJ 1 Reply Last reply
                            0
                            • S swansorter

                              @KroMignon problem solved thank you

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #14

                              @swansorter
                              So exactly what I said in the first place.....

                              1 Reply Last reply
                              0

                              • Login

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