hi
I have created an application and apparently in debug is fully functional but when compile as a release and then run it it doesn't work.
anyone knows why?
thanks
Printable View
hi
I have created an application and apparently in debug is fully functional but when compile as a release and then run it it doesn't work.
anyone knows why?
thanks
What is the error u got?Quote:
Originally posted by andreshs1
hi
I have created an application and apparently in debug is fully functional but when compile as a release and then run it it doesn't work.
thanks
There could be several reasons why your application works only in debug mode. Here are some things to check:
1) Statements that need to be executed are not in assert statements.
2) Enough memory is allocated for your variables.
It's hard to know what's going on without an error description.
Take a look at this thread http://www.codeguru.com/forum/showth...hreadid=269905
I think it will solve ur problem
also take a look at following query from another user.
http://www.codeguru.com/forum/showth...ug+and+release:wave:
Well, besides that based on your description, one could only take wild guesses...take a look at the following FAQ...Quote:
Originally posted by andreshs1
I have created an application and apparently in debug is fully functional but when compile as a release and then run it it doesn't work.
Thank you guys for the replys
the problem I have is that when I launch the application created in release mode, when I tried to connect the client to the server, the server uses 98% of the CPU.
the Server uses two thread, do you think that could be the reason, as a matter of fact I didn't set priority to any of the threads since I thought that it would be normal by default.
so, how can I find out where the problem is?
Have you read the FAQ Andreas pointed you to? (doesn't seem so, or you wouldn't use the term "release mode" any more;)) That FAQ explains how you can debug your release build. Now multithreaded applications are not easy to debug, but it's possible. It's very likely that you will be able to find out what's wrong with your release build by running it in the debugger.Quote:
Originally posted by andreshs1
so, how can I find out where the problem is?
Hi, I am reading it right now.
I am also initialising all the variables on the constructors.
Do I also have to initialise the arrays? or the arrays when created are assigned memory automatically?
That is a great faq!! congratulations!
Thanks
Not sure what you mean here... Yes, when an array is created (in either way), memory is assigned to it, of course. However, that memory is uninitialized, so you'll have to initialize the elements to meaningful values before using them.Quote:
Originally posted by andreshs1
Do I also have to initialise the arrays? or the arrays when created are assigned memory automatically?
Well...that's kind of taste, nevertheless, I usually initialize everything...pointers, variables, arrays etc. :cool:Quote:
Originally posted by andreshs1
I am also initialising all the variables on the constructors.
Do I also have to initialise the arrays? or the arrays when created are assigned memory automatically?
hello there
I have been checking what was wrong and ufffffff lots of things just doesn't work
lets start
I have a dialog class that I call at some point
this class has a constructor asCode:CUserDlg userDlg = new CUserDlg();
INT_PTR rtnDlg = 0;
int rtn = 0;
rtnDlg = userDlg.DoModal();
and on the OnInitDialog I try to initialise all the variablesCode:CUserDlg::CUserDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUserDlg::IDD, pParent)
, m_pClientDlg(NULL)
, m_existingUser(0)
, test(_T(""))
, m_userName(_T(""))
, m_passWord(_T(""))
{
}
but when I try to access them from any of the methods of the class it says that the pointers are not right
and it doesnt workCode:m_existingUser = 0;
test = _T("");
m_userName =_T("");
m_passWord="a";
how do I initialise the variables for the previous example?????
and how would you initialise an array of char such as
char myarray[25];
Thanks
Well...without showing what types these variables are...there is basically no way to answer that question. Post your class declaration.
sorry
USERDET is a structureCode:public:
CEdit* m_uNameEdt;
CEdit* m_pWordEdt;
CTCPChatClientDlg* m_pClientDlg;
BOOL m_newUser;
CString m_userName;
CString m_passWord;
int m_existingUser;
USERDET userDet;
then I also want to copy the value from m_userName into userDet.userName and I useCode:typedef struct USERDET{
BOOL newUser;
char userName[25];
char passWord[25];
}USERDET;
but the value stored in the variable is not copied properly instead I get ascii charactersCode:strcpy(userDet.userName,m_userName);
Thanks a lot for your help
Well...first of all there is no need to do the 'typedef' thing with structures in C++ since the 'struct' keyword already defines a new datatype...thusQuote:
Originally posted by andreshs1
Code:typedef struct USERDET{
BOOL newUser;
char userName[25];
char passWord[25];
}USERDET;
is enough...Code:struct USERDET
{
BOOL newUser;
char userName[25];
char passWord[25];
};
To initialize the structure properly add a constructor...
Besides that, your code looks okay...where do you use the 'strcpy()' command?Code:struct USERDET
{
BOOL newUser;
char userName[25];
char passWord[25];
USERDET()
{
newUser = FALSE;
memset(userName, 0, sizeof(userName));
memset(passWord, 0, sizeof(passWord));
}
};
When the dialog doModal return I copy the values that it got from the CEdit boxes
the userDlg.m_userName contains the correct value but when it is copied to the m_userDet.userName there are only ascii characters copies.Code:rtnDlg = userDlg.DoModal();
if (rtnDlg == IDOK)
{
strcpy(m_userDet.userName,userDlg.m_userName);
strcpy(m_userDet.passWord,userDlg.m_passWord);
//stablish connection to server
if (!cConnect->GetConnected(m_userDet))
{
I thought that it could be b'cos I needed to initialised in the constructor of the class, or maybe that the array of char is not initialised properly.
Thanks
I do not know if anyone already pointed out the article "Surviving the release version" by Joseph M. Newcomer:
http://www.codeproject.com/debug/survivereleasever.asp
I think this one is very advisable.
Oliver.
Thank you for the tip Oliver, I have read that article few times today, and I identify the problems in my code, which are the initialization of the variables, and I since I am fairly a new programmer I am going mad trying to find the way to initializate the variables
at present the problem I have is that one of the member variables of one of the classes is a struct
that struct is initialized on the struct definition but do I need to initialized also in the class constructor? if so, how do I do it??Code:struct USERDET
{
BOOL newUser;
char userName[25];
char passWord[25];
USERDET()//initialisation as Mr Masur suggested
{
newUser = FALSE;
memset(userName, 0, sizeof(userName));
memset(passWord, 0, sizeof(passWord));
}
};
at the moment without initializing the struct on the class constructor when I try to access the values of the struct these values are set and I cant modify them such as by
Any ideas why it doesn't workCode:strcpy(m_userDet.userName,userDlg.m_userName);
strcpy(m_userDet.passWord,userDlg.m_passWord);
nothing gets copied accross no even like fallow
strcpy(m_userDet.userName,"hello");
this should copy hello into the m_userDet.userName but it doesn't copy anything
Thanks
Yes, the FAQ mentioned also links to it - as a last resort. That article is indeed very good and comprehensive - the FAQ covers the most frequent causes for release build problems, and points to that detailed article in the case everything else fails.Quote:
Originally posted by Oliver Twesten
I do not know if anyone already pointed out the article "Surviving the release version" by Joseph M. Newcomer:
http://www.codeproject.com/debug/survivereleasever.asp
I think this one is very advisable.
Well...one thing I noticed is that your given example should not even compile. With the following lineQuote:
Originally posted by andreshs1
When the dialog doModal return I copy the values that it got from the CEdit boxes...
you create the dialog on the heap (using a pointer)...later on, however, you are accessing the dialog as it was created on the stack...Code:CUserDlg userDlg = new CUserDlg();
:confused:Code:rtnDlg = userDlg.DoModal();
if (rtnDlg == IDOK)
{
strcpy(m_userDet.userName,userDlg.m_userName);
strcpy(m_userDet.passWord,userDlg.m_passWord);
//stablish connection to server
if (!cConnect->GetConnected(m_userDet))
{
}
]
Other than that...could you post your project here (without debug and release directory)?
I don't understand what you mean by "initialized on the struct definition", but the code suggested by Andreas uses the struct's ctor for initialization. Which other class constructor are you referring to?Quote:
Originally posted by andreshs1
that struct is initialized on the struct definition but do I need to initialized also in the class constructor? if so, how do I do it??
Note that those problems have nothing to do with the struct members being initialized or not - the strcpy you showed should definitely copy the strings to the struct members, regardless of the previous content. So the problem must be something else - are you sure you are looking at the same instance of the struct in both cases? And since the struct instance seems to be a member of a class - are you sure you a looking at the same instance of that class?Quote:
Originally posted by andreshs1
at the moment without initializing the struct on the class constructor when I try to access the values of the struct these values are set and I cant modify them such as by
Any ideas why it doesn't workCode:strcpy(m_userDet.userName,userDlg.m_userName);
strcpy(m_userDet.passWord,userDlg.m_passWord);
nothing gets copied accross no even like fallow
strcpy(m_userDet.userName,"hello");
this should copy hello into the m_userDet.userName but it doesn't copy anything
No, you don't...the constructor will be automatically called while constructing the enclosed class (in your case the dialog).Quote:
Originally posted by andreshs1
that struct is initialized on the struct definition but do I need to initialized also in the class constructor? if so, how do I do it??Code:struct USERDET
{
BOOL newUser;
char userName[25];
char passWord[25];
USERDET()//initialisation as Mr Masur suggested
{
newUser = FALSE;
memset(userName, 0, sizeof(userName));
memset(passWord, 0, sizeof(passWord));
}
};
What? That is basically impossible. The above line will definitely copy the word 'hello' into 'userName'. Somehow I get the impression that you are copying to a local (-> different) structure than the one enclosed by the dialog class...Quote:
Originally posted by andreshs1
strcpy(m_userDet.userName,"hello");
this should copy hello into the m_userDet.userName but it doesn't copy anything
ok, I am posting the application, I have left break points where the problem is detected, hope you manage to understand, thanks in advance for all your help
once the application is launched, go the the menu and click connect
Thanks
Oops, a VC++ .net project... Sorry, I won't be able to participate in the debugging party then... :( ;)
Well...I do not have any development IDE installed at the moment, and I just saw that you are using .NET. Thus, I simply looked over the code...
- Run your application within the debugger and step into the constructor of 'CTCPChatClientDlg' and take a look what the value of 'm_userDet.passWord' and 'm_userDet.userName' is after doing the 'strcpy()'.
- The following does not make sense to me and should not make it through the compiler...
'new' returns a pointer...henceCode:CUserDlg userDlg = new CUserDlg();//here were I create the instance of the dlg
would be correct... :confused:Code:CUserDlg *userDlg = new CUserDlg();//here were I create the instance of the dlg
- Run your application within the debugger and step into the function 'OnConnectMenu()' and take a look what the value of 'm_userDet.passWord' and 'm_userDet.userName' is after doing the 'strcpy()'.
What...you need a physical debugger to debug code?? :D :D :DQuote:
Originally posted by gstercken
Oops, a VC++ .net project... Sorry, I won't be able to participate in the debugging party then... :( ;)
Well, we're all getting older... :DQuote:
Originally posted by Andreas Masur
What...you need a physical debugger to debug code?? :D :D :D
ok, lets see
on the constructor the values are ok, but I tried to to a test such as
Code:
CTCPChatClientDlg::CTCPChatClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTCPChatClientDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//structure definition
m_socket = 0;
m_userList.status = 0;
m_userList.UserId= 0;
m_dlgCounter = 0;
m_userDet.newUser = 0;
strcpy(m_userDet.passWord,"test");//the values here are not modified, why????
//the new value should be "test"!!!!!
strcpy(m_userDet.userName,"test");
}
Thank you, Mr Masur and Mr gstercken
OK, OK, just a little doubt... You are debugging the release version, right? Remember (from the FAQ) that the current line you see in the debugger doesn't always exactly correspond to the actual line being executed (due to optimizations)? Try stepping a few lines further and see if the values change.
Is he still? That would of course explain some things... :cool:Quote:
Originally posted by gstercken
OK, OK, just a little doubt... You are debugging the release version, right? Remember (from the FAQ) that the current line you see in the debugger doesn't always exactly correspond to the actual line being executed (due to optimizations)? Try stepping a few lines further and see if the values change.
I am very very sorry guys, you are right, I didn't remember that sometime the line I see is not updated and I wasn't continueing with the debbuging.
Sorry and Thanks!!
another problem I now have is that I use a variable which stores the value of the created socket, but I can only use it once because the second time the values is gone, any ideas why??
Any suggestion?Code:
ioctlsocket(m_socket,FIONREAD,&size);//here the value of socket it is fine
while(size > 0)
{
rtn = recv(m_socket,buff,strlen(buff),0);//the value of socket disappears,
//and doesn't receive anything
if(rtn == SOCKET_ERROR)
{
AfxMessageBox("****"+m_socket);
}
str += buff;
size = size - rtn;
}
strcpy(buff,str);
ptrPacket = (PACKET*)buff;
Thanks
Yes, that code looks ugly. You are using strlen(buff), not the real buffer size. strlen() will just scan the buffer (and the memory after it) until it finds a NUL character, so you will get any arbitrary value. recv will use that value, and if it is higher than the actual buffer size, it will overwrite memory after the buffer (in your case, appearently it hits at least m_socket). So make sure you pass the actual buffer size, don't use strlen for that.Quote:
Originally posted by andreshs1
Code:ioctlsocket(m_socket,FIONREAD,&size); //here the value of socket it is fine
while(size > 0)
{
rtn = recv(m_socket,buff,strlen(buff),0); //the value of socket disappears,
//and doesn't receive anything
...
}
It WORKSSSSSSSSS!!!
I want to thank everyone who posted in this thread trying to help me, mainly Andreas Masur and gstercken.
Thank you guys.
NB. but dont worry, I will keep posting :D
Quote:
Originally posted by andreshs1
It WORKSSSSSSSSS!!!
I want to thank everyone who posted in this thread trying to help me, mainly Andreas Masur and gstercken.
Thank you guys.
NB. but dont worry, I will keep posting :D
would have worked on the 10th too :D
http://www.codeguru.com/forum/showth...hreadid=282532
:D I completely missed that thread... The most frightening thing is the adviceQuote:
Originally posted by Mick
would have worked on the 10th too :D
http://www.codeguru.com/forum/showth...hreadid=282532
Well, at least he lives up to the motto in his signature... :rolleyes:Quote:
Originally posted by Ness
this has happened to me b4, so what I did is declare my int's data on a different line.
Quote:
Making the forums a dirtier place...