Results 1 to 3 of 3

Thread: Program error while executing, ok while debugging

  1. #1
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Program error while executing, ok while debugging

    Hello!
    My program behaves in a very strange way! When I run it in debug step-by-step mode all goes good but when I run it in "normal" mode it raises a segmentation error around a dynamically allocated vector! As I said this error doesn't come up while debugging...

    Here is the link to the project (I've uploaded it to mediafire) http://www.mediafire.com/?vbwre2a73vl8ju9

    This program simply has to find a path between two nodes of a graph.
    Starting from the node 0 (first row of the adjacency matrix) it inspects all the nodes searching for the first uninspected node which is the end node (fourth row).

    I've posted a light version of the project with only the necessary to raise up the segmentation fault (infact it is a fixed graph, etc...)

    Ask me if you need more info

    thanks a lot
    Last edited by harmodrew; 11th August 2010 at 02:03.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Program error while executing, ok while debugging

    Not much Qt code in your project is there?

    Don't know if these are causing your seg fault or not but here are two things that I noticed:
    • realloc() can move the memory block so you need to return the pointer to the calling function.
    • check your deletes

  3. #3
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program error while executing, ok while debugging

    realloc() can move the memory block so you need to return the pointer to the calling function.
    here I use realloc()...what's wrong?

    Qt Code:
    1. void AddInspectedNode(int idxNode, int *Inspected, int *nInspected)
    2. {
    3. (*nInspected)++;
    4. Inspected = (int *) realloc(Inspected, (*nInspected) * sizeof(int));
    5. Inspected[(*nInspected)-1]= idxNode;
    6. }
    To copy to clipboard, switch view to plain text mode 

    check your deletes
    I've changed the Graph destructor into:
    Qt Code:
    1. Graph::~Graph()
    2. {
    3. for (int i = 0; i<nNodes;i++)
    4. delete [] mat[i]; //THIS CHANGED
    5. delete [] mat;
    6. }
    To copy to clipboard, switch view to plain text mode 

    and the CheckPath method of Graph:
    Qt Code:
    1. int Graph::CheckPath(int idxEntry, int idxExit)
    2. {
    3. int result, nInspected, *Inspected, i;
    4.  
    5. result = nInspected=0;
    6. Inspected = new int[1];
    7.  
    8. PathExists(idxEntry, idxExit, mat, nNodes, Inspected, &nInspected, &result);
    9.  
    10. delete [] Inspected;
    11.  
    12. //DON'T NEED TO DEALLOCATE HERE THE MATRIX
    13. /* for (i=0; i<nNodes; i++)
    14.   delete [] mat[i];
    15.   delete [] mat;
    16. */
    17. return result;
    18. }
    To copy to clipboard, switch view to plain text mode 

    but still get the error...

Similar Threads

  1. Replies: 4
    Last Post: 14th September 2011, 01:18
  2. Error while executing a application - Gtk WARNING
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2010, 12:25
  3. Replies: 2
    Last Post: 22nd July 2009, 14:14
  4. Error executing SELECT query with QSQLITE
    By garfield85 in forum Qt Programming
    Replies: 6
    Last Post: 25th May 2009, 18:05
  5. finding the time interval of executing a program
    By babu198649 in forum Qt Programming
    Replies: 1
    Last Post: 13th December 2007, 12:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.