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. Solved - Segementation Fault
Forum Updated to NodeBB v4.3 + New Features

Solved - Segementation Fault

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 8.8k Views 1 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.
  • S Offline
    S Offline
    sprl111
    wrote on last edited by
    #1

    Hello,

    My program is getting a segmentation fault (SIGSEGV signal from Windows 7) while reading a file. The file is an ASCII file with 8380232 lines of text (238 MBytes in size). Each line of text consists of two real numbers seperated by a space. The code below basicially reads and parses each line, converts the strings to doubles and stores the double values in two arrays. I'm stepping through the code with a debugger and all seems well. So, I hit continue and at line 564 (two out of three times, other time it bombed at line 3) of the input text file I get this signal/error. I looked at the data file and nothing unusual is happening there. The code is below along with what was in the compile output window. Does anyone have any knowledge of what might be happening to cause this?

    Thanks you.

    @
    // N8241A::updatewaveforms -> read waveform file & update N8241A AWG waveforms
    void N8241A::updatewaveforms(QString filename)
    {
    QFile file;
    QString qline;
    int index;
    int count;

    file.setFileName (filename);
    if ( file.open(QIODevice::ReadOnly) )
    {
        // file opened successfully
        QTextStream t( &file );        // use a text stream
    
        // until end of file...
        count = 0;
        while ( !t.atEnd() ) {
          // read and parse the command line
            qline = (t.readLine()).trimmed();         // line of text excluding '\n'
            index = qline.indexOf(" ");
            ch1_testvector[count] = (qline.mid(0,index)).toDouble();
            ch2_testvector[count] = (qline.mid(index+1)).toDouble();
            count += 1;
        }
        // Close the file
        file.close();
    }
    else
    {
        appendPlainText("N8241A initialization: Unable to open test vector file \n >");
        return;
    }
    

    @

    @
    Debugging starts
    Critical error detected c0000374
    (Internal error: pc 0x1 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x1 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x1 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x1 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x0 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x1 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x1 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x1 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x1 in read in psymtab, but not in symtab.)
    (Internal error: pc 0x0 in read in psymtab, but not in symtab.)
    Debugging has finished

    Debugging starts
    Debugging has finished
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      Why not use a QVector or QList for the ch1_testvector and use ::append? Maybe your count exceeds the bounds of those arrays.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sprl111
        wrote on last edited by
        #3

        Thanks for replying. I'll look into QVector and QLIst. I'm new to QT. I've sort of grown accustomed to and spoiled by .net/managed code, C++/CLI and C#. I stare at my C++ code here and often don't even see memory bounds issues since I rarely have to concern myself with these things with a memory manager and managed pointers in the Microsoft world.

        Well, meanwhile here's my array declarations and instantiations. There should be enough room for the data.

        @
        double* ch1_testvector;
        double* ch2_testvector;
        .
        .
        .
        ch1_testvector = new double [8388608];
        ch2_testvector = new double [8388608];
        .
        .
        .
        @

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sprl111
          wrote on last edited by
          #4

          By the way, I think I figured out what was happening. I don't think my class was getting instantiated. I didn't know non-static funcitons of a class would even begin to run without the class being instantiated.

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            Hi, indeed as mentioned before it is a good idea to use Qt storage classes. Then you don't have to think about clearing memory when done with the data. In your case you should! When it is just double you need you can use the QList<double> myList and append any new ones. This is also valid for pointers (QList<double*> myList).
            Happy coding!

            Greetz, Jeroen

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pivonroll
              wrote on last edited by
              #6

              When you use the debugger always check for pointer to an object before you are calling some method using that pointer.
              And also always use RAII idiom. It helps a lot.

              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