Results 1 to 7 of 7

Thread: Different behaviour between release and debug version

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Different behaviour between release and debug version

    Hi !

    I am developping a serial data frame decoder based on the Win_QextSerialPort class that can be found on sourceforge.

    It works quite well in debug mode and never crashes but when I launch the release version it crashes, telling me that an instruction uses memory adress 0x00000000 and that memory cannot be written ... in fact it is an access violation

    My problem is that it never happens in debug version but always in release version, why ?

    Another thing, how could I make to know the line and file where this access violation occurs in release mode ?

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Different behaviour between release and debug version

    In this case use printf or qDebug for catch crash,and it will be helpful in fufture if all your dangers code blocks will be wrap in try...catch() blocks
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Different behaviour between release and debug version

    Quote Originally Posted by yellowmat
    My problem is that it never happens in debug version but always in release version, why ?
    Because in debug mode some additional checks are made, like asserts, etc. release mode doesn't have asserts, so for example if you had:

    Qt Code:
    1. void xxx(QObject *o){
    2. Q_ASSERT(o!=0);
    3. //...
    4. o->deleteLater();
    5. }
    To copy to clipboard, switch view to plain text mode 
    It would abort on assert in debug mode if o==0, but not in the release mode (it would abort a while later when trying to dereference a null pointer ).

    Another thing, how could I make to know the line and file where this access violation occurs in release mode ?
    In your case this is a null pointer somewhere. If you check for those before dereferencing pointers, you'll catch your bug, no matter if you use debug or release mdoe.

  4. #4
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Different behaviour between release and debug version

    Basically you gotta look over your code and make sure you are initializing everyhing, you are deleting everything correctly (and setting it to 0), and that you are checking for null pointers. These release vs. debug type of errors are pretty tricky. This may be of some use:

    http://www.codeproject.com/debug/survivereleasever.asp

    Bojan
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

  5. The following 2 users say thank you to Bojan for this useful post:

    yellowmat (3rd March 2006), yop (6th March 2006)

  6. #5
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Different behaviour between release and debug version

    I will check my code those days and give my answer as soon as possible.

    Thanks every body

  7. #6
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Different behaviour between release and debug version

    Bojan, I read this article you gave me the link of, it is very interesting ... and then I checked my code. Quickly I remember that I did
    Qt Code:
    1. char* buffData = 0;
    2. buffData = new char[bytesToRead];
    3.  
    4. bytesRead = comPort->readBlock(buffData, bytesToRead);
    5. buffData[bytesRead] = '\0';
    6. comPort->flush();
    To copy to clipboard, switch view to plain text mode 

    This code is supposed to get a block of memory and add a null character at the end of the buffer ... this version worked well in debug but not in release.

    After reading the article I change
    Qt Code:
    1. buffData = new char[bytesToRead];
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. buffData = new char[bytesToRead+1];
    To copy to clipboard, switch view to plain text mode 
    and it is now working in release version as it is in debug version.

    ... thnaks for this article, I will take (much more) care of what I am allocating and writing to

  8. #7
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Smile Re: Different behaviour between release and debug version

    hai,

    I don't that this is not the problem of Debug/release mode , Instead this is logic probs.


    Say for eg :-


    Char *myChar = new [ 5 ]; // 5 = size of array

    Let's look on that array :

    0 1 2 3 4 // Index of array ie; myChar( 0) = A , myChar(1) = B ...etc.
    ---+---+---+---+---+
    A | B | C | D | E | // This is the array we are discussing..
    ---+---+---+---+---+

    NB: So we cann't say that myChar(5) = '\n'; as there is no myChar(5) .
    instead we can say myChar(size-1) ='\n' or myChar(4) = '\n'



    I think this is the solution

Similar Threads

  1. Replies: 5
    Last Post: 5th October 2008, 05:12
  2. Building debug version under VS2008
    By KenW in forum Installation and Deployment
    Replies: 1
    Last Post: 2nd May 2008, 19:09
  3. Need debug and release versions of Qwt?
    By Tiansen in forum Qwt
    Replies: 1
    Last Post: 28th March 2008, 07:55
  4. Replies: 2
    Last Post: 20th July 2007, 16:34

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.