PDA

View Full Version : Different behaviour between release and debug version



yellowmat
2nd March 2006, 16:29
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 :o

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

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

Thanks in advance.

zlatko
2nd March 2006, 16:43
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

wysota
2nd March 2006, 17:37
My problem is that it never happens in debug version but always in release version, why ? :confused:

Because in debug mode some additional checks are made, like asserts, etc. release mode doesn't have asserts, so for example if you had:


void xxx(QObject *o){
Q_ASSERT(o!=0);
//...
o->deleteLater();
}
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.

Bojan
2nd March 2006, 20:30
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

yellowmat
3rd March 2006, 10:26
I will check my code those days and give my answer as soon as possible.

Thanks every body

yellowmat
6th March 2006, 13:10
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


char* buffData = 0;
buffData = new char[bytesToRead];

bytesRead = comPort->readBlock(buffData, bytesToRead);
buffData[bytesRead] = '\0';
comPort->flush();


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

buffData = new char[bytesToRead];

to

buffData = new char[bytesToRead+1];

and it is now working in release version as it is in debug version.

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

joseph
10th November 2006, 11:38
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