Random crash when the program starts



  • Hello,

    I'm on linux (Fedora 16) and i use the last version of Qt SDK and Qt Creator.

    I have a bug with my program : it crashes randomly at starting.

    The program ask you to select a folder, then, a window appears and verifies all files contains in this folder, and finally, this windows closes and the main window appears.

    So the main.cpp is :
    @int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QString fileName = QFileDialog::getOpenFileName(0, "Fichier de donnees", "../", "graph.chrono");
    size_t pos = fileName.toStdString().find_last_of("/");
    string nomdossier = fileName.toStdString().substr(0, pos);
    
    if(!fileName.isEmpty())
    {
        Config::getConfig()->General->DATA_PATH = nomdossier + "/";
        Config::getConfig()->loadConfig();
    }
    
    firstWindow myF;
    myF.exec();
    SecondW fen;
    fen.showFullScreen();
    
    return app.exec();
    

    }@

    So, when myF is closed, the second window is instanciate and set visible.

    But there is a bug when the firstWindow is closed, randomly, the program crashes. The problem occur when fen is being created, I put some cout on its constructor and the program don't crashes every times at the same line...

    How can i diagnostic the problem ? With the debugger, the program don't seems to crashes... Is it kidding me ?

    If i remove these lines :
    @firstWindow myF;
    myF.exec();@
    The program starts successfully, it never crashes.

    So i don't understand, if it's the firstWindow which cause the crashes, why this crashes occur when the second window is creating ?

    Thanks advance for your help and i'm sorry for my bad english !



  • Hard to say without knowing what's inside SecondW. Does it crash on the constructor or on calling showFullScreen()?



  • the .cpp of the SecondW have 1222 lines, and a lot of .h because there are attributes of my others classes, So i think i can't put it here,

    The program crashes on the constructor, i put some COUT on it, in order to know where it crashes but it's not at the same line every times. So it's very difficult to diagnostic that alone...

    Thanks for your response,



  • You should try to run it in a debugger then, that throws you at the excact line where the crash occurs.

    To me it sounds like some uninitialized pointer that you try to use. But that's just a guess in the dark.



  • Other people can not give your much help unless you give useful information.

    Write a small program which can be used to reproduce the same issue is better. In most cases, a program like this will less than 100 lines.

    However, you can give a try:

    1. remove
      @
      myF.exec();
      fen.showFullScreen();
      @

    2. Using zero-interval QTimer to call your myF's exec()

    @
    QTimer::singleShot(0, &myF, SLOT(....));
    @

    1. Call fen.showFullScreen() when your myF is finished
      @
      app.connect(&myF, ..., &fen, ...);
      @


  • In the debugger, it seems to have a different behaviour. The program never crashes in the debugger... So i can't use it to know where is the problem,

    Yes it can be a pointer as you said, but the program would be always crashes, no ?

    If you wants, i can host the code on pastebin for example, if you are interested by my several crashes^^

    Thanks for your time and your responses,



  • [quote author="1+1=2" date="1334180795"]Other people can not give your much help unless you give useful information.

    Write a small program which can be used to reproduce the same issue is better. In most cases, a program like this will less than 100 lines.

    However, you can give a try:

    1. remove
      @
      myF.exec();
      fen.showFullScreen();
      @

    2. Using zero-interval QTimer to call your myF's exec()

    @
    QTimer::singleShot(0, &myF, SLOT(....));
    @

    1. Call fen.showFullScreen() when your myF is finished
      @
      app.connect(&myF, ..., &fen, ...);
      @

    [/quote]

    Hello,

    I do what you said, so :
    @firstWindow myF;
    QTimer::singleShot(0, &myF, SLOT(exec()));
    SecondW fen;
    app.connect(&myF, SIGNAL(accepted()), &fen, SLOT(showfullscreen());@

    And now, in 30 runs, there is only 1 crash... It's "negligeable" i think.... It's better than before !!

    I'm interrested with this code, so what is the difference between instanciate 2 windows and show them normally, or, use QTimer and signal for show these windows ? If you can explain me that, it will be very great !

    I have another question :
    When i use exit(0) on a method in the second window, it closes the application. It's normal, i know, but if I use :
    @QCoreApplication::instance()->quit(); @
    or
    @qApp->quit();@
    The program don't closes... Do you have an idea ? Because someone tell me, it's more "cleanly" to use quit instead of exit(int). quit() is for Qt, it clean up

    Thanks for your help,



  • When i run it on a terminal, if it crashes, it return : "segmentation fault ( core dumped )", what does that means ?

    Thanks


  • Moderators

    [quote author="darkfreed" date="1334311632"]When i run it on a terminal, if it crashes, it return : "segmentation fault ( core dumped )", what does that means ?
    [/quote]

    A segmentation fault is a result when memory is accessed in a wrong way.
    Typical reasons are array index overrun. Using of uninitialized pointers or deleting memory more than once.

    Most likely the patch you have added was just hiding your problem. It did not solve anything. You should follow Volker's advise and use the debugger to find where it crashes. This might give you a clue.



  • Yes i'm agree with you but with the debugger i have no crash, all works perfectly so it don't detect anything.

    I'm currently installing Valgrind and i will test with the core file, if i can find where it crashs

    thanks


  • Moderators

    using different tools may help to find your problem. Also downsizing of functionality may help in isolating it.
    Good luck!



  • Maybe i find the problem with gdb and the core file...

    It said me the program crashed here :
    @ptrIndexTeleport=&(ptrConstel->satellite[i]->versAntenneSol[direction-SV_FL1].indexTeleport);
    ptrIndexAntenneTeleport=&(ptrConstel->satellite[i]->versAntenneSol[direction-SV_FL1].indexAntenneTeleport);@

    So i put 2 cout :
    @cout << "ALL: " << ptrConstel->satellite[i]->versAntenneSol[direction-SV_FL1].indexTeleport << endl;
    cout << "ptrIndexTeleport : " << *ptrIndexTeleport << endl;@

    And when the program works, ALL have a wrong value (example : 146963252), and ptrIndexTeleport is 3. When the program crashed, the two values are eguals and it's 25369325 (a random number). So i think something is bad initialized, and it will be hard to find what.

    I'm on it,

    thanks


  • Moderators

    If this causes ultimately your crash, it still may be only a symptom. But you got a handle to start your investigation.

    It does not look that you need advise at the time then.



  • Yes, maybe the problem isn't from here but GDB stopped at this line and said there is an error.

    I tryied to launch with gdb many times and it always stop at the same line.

    If i can resolv that, maybe i will be abble to restart with gdb and resolv another bug (if exist !)

    Thanks for all, if you have advise, it will be great, i'm a noob !! :)


  • Moderators

    Well, since you know there is a problem and what is wrong you got already a start.

    You need to check whether the information in question has been introduced already corrupted or if it happens during some execution of code.

    You are lucky that you are getting the stop always at the same line. This is not always the case.

    Apparently, you are also lucky that the problem does not occur after 10 hours of processing. This helps you to track the problem faster.

    Typically I would start at the point where in the information shows up first time in your application. When it is ok at this point the problem comes later. Try to figure out where it might happen. Eventually you have to introduce new access to the data structure. Just for checking if it is still ok.

    Another friendly advise: Do backups regularly! And keep track of how you do the backup. A mess of different files you do not understand the timely sequence is the least you can tolerate. One easy way to do such backups is simply copying the source to somewhere else (e.g. using an archiving program like zip and use date and time as file name of zip).



  • Okay thanks for all your advice !

    I put 2 cout where it crashes, and I can see :
    --> ptrIndexTeleport n°1 : 1817910664
    --> ptrIndexAntenneTeleport : 50

    It's TOTALLY WRONG, the maximum of AntenneTeleport is 4 instead of 50, same is for ptrIndexTeleport...

    @ptrIndexTeleport=&(ptrConstel->satellite[i]->versAntenneSol[direction-SV_FL1].indexTeleport);@

    So the problem is there. The first value is concerned, but if the problem is the initialization, the program will crash every time I think.

    Thanks for your help,


  • Moderators

    You got a sequence of statements between initialization and crash pointing to the particular data.

    I can guess only, that this are only the symptoms, but not the cause. Therefore, you need to check when it is OK and when it is corrupted.

    Beware the data might be changed somewhere, where you do not expect at all. That is the basis of my recommendation.



  • I used to run QtSDK 4.8.1 on FC16. (I didn't use Creator.) I had a LOT of problems with random crashes but mine were the other way round - always ran fine normally but crashed with gdb(7.3.50.20110722-13.fc16). They were bad crashes too which smelled like incorrect linkage or memory allocation. I downloaded the Qt source and compiled from scratch; recompiled my Qt App; downloaded all Fedora debug-info packages. It is MUCH better. Normal and debug sessions hold up pretty well.

    Bob



  • Hi,

    After some years of research, i think i've found the problem.

    The variable that contains a crazy value is initialized in the first thread.
    And, this variable is used in the second thread.

    When the program starts, it do that :
    @lesLiensEtDebits.Traiter(index);
    lesObs.Traiter(TraitementObs::DROPSETCHARGES);@

    NOTE : Traiter( ... ) is a method which start the thread with start().

    I put one cout where the 1st thread begin, and another when the 2nd one begin too.

    When the program starts successfully, there is "one" and "two" at the output.
    When the program CRASHS, there is "two" and "one" !! IT'S CRAZY ! The second thread began before the first one !!

    So, i trying to do that correctly, so something like
    @lesLiensEtDebits.traiter(index);
    connect(&lesLiensEtDebits, SIGNAL(finished()), &lesObs, SLOT(Traiter(TraitementObs::DROPSETCHARGES)));@

    But the program said me an error , it don't find this slot..
    The slot is
    @ void Traiter(TraitementObs::type _choix );@

    So i want to pass a parameter in the slot, i don't know if we can do that.

    Any idea for how to start the 2nd thread AFTER the 1st one finished ?
    Thanks for your help,


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.