Jump to content
  • Advertisement
Sign in to follow this  
commy2005

Release error but DEBUG no erro

This topic is 4781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I need some advice.I recently finished my game and when I compiled in RELEASE mode,it give me an error.But when in DEBUG mode,it didn't crash.Anyone encounter this before? Eventually it encounter the crash in the malloc section(I even changed it to new too).But when run it in DEBUG mode compilation it will be fine..no crashes.Hope someone can help me out on this. regards, Commy2005

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Before anybody can answer you might want to include the error message it crashes with to give people something to go on.

Cheers

Share this post


Link to post
Share on other sites
Quote:
Original post by commy2005
Hi everyone,

I need some advice.I recently finished my game and when I compiled in RELEASE mode,it give me an error.But when in DEBUG mode,it didn't crash.Anyone encounter this before?


Some things to check:

1. Asserts and other debug statements: make sure your asserts are correctly written. It's surprisingly easy to write something like: assert(x = y); which can cause annoying release only bugs.

2. Make sure you're not writing past the end of any arrays. In debug mode, the compiler will add some padding to the end of the arrays so it can check for buffer overflows - it will run OK although it should warn you of any overruns. In release mode, there's no such buffer, and overwriting the array will trash some other data.

3. Some compilers will automatically initialize everything to 0 in debug mode, but not in release mode, instead leaving it with a random value. If you try and call free() or delete on a non-null pointer that doesn't point to valid memory, it will cause the crash. Make sure pointers are intialized to null.

Step through the code in the debugger and pay close attention to any warnings that are in the output. Try and isolate the exact spot in the code that goes wrong, either by using the simple technique of sticking message boxes your code so you can see how far it gets, or by changing your compiler settings to build release builds with symbols so you can use the debugger.

If none of the above help, post the offending chunk of code on here and we'll see if we can spot it.

Share this post


Link to post
Share on other sites
Thanx for the info.I put on some code here to see whether anyone could identify it.Putting the char *variable to null are one of my concern.I actually didn't do that.So I will look into it.



#include "my.h"
#include .....

char *myWord;

void my::copyWord()
{
FILE *myfile=fopen("data.txt","r"); //two lines of data john,second line doe
char str[256];
int i;

while(!feof(myfile))
{
fscanf(myfile,"%s",256)
{

myWord=(char*)malloc(strlen(str)); //after tracing for hours,malloc prob
for(i=0;i<=strlen(str)
myWord=str;

}
}

fclose(myfile);
}




If I don't call this copyword function,no malloc happening then no crash on RELEASE compilation. Hope you guys able to help out.As usual the crash pop-up a message window stating "Memory cannot be written".send report or don't send report window.Thanx in advance.

Share this post


Link to post
Share on other sites
Quote:
Original post by commy2005
fscanf(myfile,"%s",256)


Gah!

That's your problem. You probably want something like:

fscanf(myfile,"%255s",str);

As it is, you're copying the data to memory location 256, which almost certainly not a safe or sensible place to keep it.

Also, you should probably check the file pointer myfile to make sure the fopen() succeeds, as well as the myword pointer to make sure that the malloc succeeds.

[Edited by - Sandman on April 25, 2005 7:16:40 AM]

Share this post


Link to post
Share on other sites
Thanx Sandman!I change it later and get back to you tommorrow.So you mean if i put 256 will get error in RELEASE mode?As you mentioned,DEBUG mode will patch up here and there for me.But RELEASE mode won't help me patch here and there?

So I think I should change it to 255 instead of 256 at

fscanf(myfile,"%s",255)??

Can I assumed that if DEBUG mode works,it should works in RELEASE mode too?

Hope that really helps.:D

Thanx again!!!:D

Share this post


Link to post
Share on other sites
Quote:
Original post by commy2005
So I think I should change it to 255 instead of 256 at

fscanf(myfile,"%s",255)??


No, that's still going to cause the same problem! You want to copy exactly what I wrote. The last parameter of fscanf should be a pointer to a valid region of memory to copy the data into. Neither 256 or 255 can be guaranteed or even expected to be valid pointers to memory you can access.

You pass in str as the last parameter of fscanf, and you can specify the max number of characters to read in the format string. The use of 255 instead of 256 leaves space for a \0 character to mark the end of the string.


fscanf(myfile,"%s", 255); // WRONG
fscanf(myfile,"%255s",str); // RIGHT




Quote:

Can I assumed that if DEBUG mode works,it should works in RELEASE mode too?


In an ideal world, yes, but in reality it's not really a safe thing to assume as there are a number of bugs that don't manifest in debug builds. As written, I can't imagine that your copyword function could be working at all. I can only guess that it isn't, but is somehow not all that important to the overall functioning of your program.

Share this post


Link to post
Share on other sites
Thanx alot Sandman,I actually fixed my own problem.I actually added 2 parameter for compilation which are not included in the RELEASE version.I actually added

/FORCE:MULTIPLE
/FORCE:UNRESOLVED

to my Commandline parameter for compilation,I didn't add them to RELEASE.Thanx for your time.

BTW,I was actually write a mistake in the fscanf(....,255),but actually I meant fscanf(...,str).I did a mistake there while I rewrite the code in the forum.I didn't cut and paste.Thanx a million and good advice on the checking,like pointers must be NULL and etc....

cheers,
Commy2005

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!