Click to See Complete Forum and Search --> : Release Mode
LHoffman
August 3rd, 1999, 12:48 PM
First of all this is an excellent site. Now my problem. When I compile my app for debug mode it works great. When I compile it for Release mode and run the program it bombs at the CString.Mid() method.
Now I changed the C++ code generation in the use run-time library from "Multithreaded" to "Debug Multithreaded" and it seems to be working great.
Does anyone have any suggestions why this would work. Is this a permanent fix.
Thanks
-LHoffman
Paul McKenzie
August 3rd, 1999, 12:59 PM
Instead of changing the library for the Release Version, you should have only changed the "Debug" setting to "Program DataBase" and recompiled your app. This way, you could use the debugger to debug the release version. This technique is documented in CodeGuru, but it seems that hardly anyone ever uses it.
The problem with using the Debug MultiThread is that if you ever wish to distribute your program to other people, they will probably *not* have the multithreaded debug version of the library installed already. The debug library is meant for developmental purposes and should not be used in the regular distribution to other users. The only MFC libraries that are installed on the everyday user's computer (persons who do not have MSVC on their machine) are the release versions of the MFC libraries.
Regards,
Paul McKenzie
Paul McKenzie
August 3rd, 1999, 01:06 PM
Also, you do have a bug in your program. The Debug version of the libraries just mask the bug from you. Your Mid() function is probably going out of bounds.
Like I suggested in the previous message, recompile the release version with debug info, *and* specify that you want to include debug info in the release version's Link settings (I forgot to mention that step, sorry). You will then find the error much easily.
Regards,
Paul McKenzie
LHoffman
August 3rd, 1999, 01:30 PM
Paul,
Thanks for the help. I have done as you suggested. It still doesn't work. Let me explain what I am attempting to do.
My program simple parses a file. I take the information contained in this file and extract out a key word. This key word now becomes a node in a tree structure. Much like Windows Explorer. When the user clicks on this node, the associated text for that node pops up in a CEDit window.
My program only crashes when I open this one file in Release mode. I can open other files without any problems. When I run my program in Debug mode and open the file that crashes in Release mode it works great.
I compare the file that crashes in Release mode to another one that I know I can open. They both check out. I can't find anything different between these two files except for the text it contains.
What do you think???
Thanks
-LHoffman
Paul McKenzie
August 3rd, 1999, 02:24 PM
Does the crash occur on the actual file open call, or when you have already opened the file and doing some processing?
Regards,
Paul McKenzie
LHoffman
August 3rd, 1999, 02:54 PM
Paul,
The crash happens after I open the file. It occurs when I do a CString.Mid() on the string.
-Larry
Paul McKenzie
August 3rd, 1999, 04:13 PM
The parameters to Mid() are
- a valid CString
- valid starting position and count.
Why not display what you are trying to do Mid() on as well as the start and length parameters by using AfxMessageBox()?
// Use regular character buffer;
char szBuf[100];
wsprintf(szBuf, " Start: %d\nLength:%d", start, length);
AfxMessageBox(MyCString + szBuf);
Also, if you do have a release build with debug info, you could just place a breakpoint on the Mid() call to see if everything is OK.
Regards,
Paul McKenzie
LHoffman
August 4th, 1999, 09:06 AM
Paul,
What I did before was placed an AfxMessageBox right before the crash. It worked up to that point. Then I placed another messagebox after the CString and it crashed. I made sure the length of the CString was valid and also the CString itself. I printed these values to the screen to make sure they were in fact valid. All the values seemed to be correct.
Paul McKenzie
August 4th, 1999, 12:53 PM
Sounds like a tough problem. The only thing I could suggest is to try to write something other than the values to the archive and see if the problem is still there. It may also be that you have a memory overwrite that screwed up a few things and is manisfesting itself within the archiving portion of the code.
Regards,
Paul McKenzie
Rail Jon Rogut
August 4th, 1999, 04:06 PM
Could you show us the area of your program where the crash is occuring, as well as the value of the CString object and the parameter values for the call to CString::Mid()? Also show us where the CString object is defined and a value assigned to it.
Rail
Recording Engineer/Software Developer
Rail Jon Rogut Software
railro@earthlink.net
http://home.earthlink.net/~railro/
LHoffman
August 5th, 1999, 08:16 AM
Here is my code segment:
CString cstrsaved, cstrAttribute, csReturnedComments;
CString cstrLeft, cstrRight, cstrlabelName;
CString cstrRVal;
int iAttributesIndex, iFoundIndex, i = 0, icount = 0, iFindPeriod, ireverse;
int iBeginning;
BOOL bExit = false;
CString EntireLineOfAttribute;
//This variable is used as a temp register. So that
//the origial SCSourceCode would never change.
SXrcCString SXTemp;
//======================================================================
//======================================================================
// Find the attribute field and strip out the entire line.
//======================================================================
//======================================================================
//Find the substring and store the index where substring was found.
iAttributesIndex = cstrSourceCode.Find(theOP1AtrributesDataBaseItem->cLabel);
//Check to make sure that the search parameter was found and
//skip over the search paramters who's inLink has been initilized
//to true. This will make sure we don't get an unwanted searches!
if (iAttributesIndex != -1 && !theOP1AtrributesDataBaseItem->inLink)
{
CString cstrAtt = theOP1AtrributesDataBaseItem->cLabel;
int iLenOfAtrributeField = cstrAtt.GetLength()-1;
char cstrrt = cstrSourceCode.GetAt((iAttributesIndex+iLenOfAtrributeField));
int ivalue = (int)cstrSourceCode.GetAt(((iAttributesIndex+iLenOfAtrributeField)+1));
//Extract out everything from the beginning to the "found"
//search string parameter's index. i.e the left side of the
//string will be returned.
CString cstrLeft = cstrSourceCode.Mid(0, iAttributesIndex);
//Find the line feed paramter, starting from the end of the string.
ireverse = cstrLeft.ReverseFind('\n');
//Need to increment this parameter by one. Why you ask?? because
//this is the index where the '\n' was found. This gives us the
//wrong position into the string. The correct position is up 1. So
//we need to add one to this count. This will give us the correct
//position into the string. Now we are pointing at '\r', not '\n'.
ireverse = ireverse + 1;
//Return 1st half of the attribute field. i.e "currentSurvey.systemGlobal[@"
CString cstrLeftPartOfAttribute = cstrLeft.Mid(ireverse,cstrLeft.GetLength()-/*1*/ireverse);
//Return the source code up to the point where the attribute
//field was found. This will be used later to extract out
//the comment field.
cstrLeft = cstrLeft.Mid(0, ireverse);
The problem is this CString cstrSourceCode.Mid(). Like I said any other files this works great. But, when I open this certain file it crashes.
-LHoffman
Rail Jon Rogut
August 5th, 1999, 04:43 PM
Okay
The first thing that caught my attention is the scope of your CString variables and the fact that you have two variables with the same name (CString cstrLeft) -- First, what happens when you declare all your CString variables at the top of the function instead of inside the brackets, which limits their scope.
I did try creating a segment of code in a test project here as:
CString cstrSourceCode("H:\\Test\nname\\folder nest\\test.exe\nTest some more");
Recording Engineer/Software Developer
Rail Jon Rogut Software
railro@earthlink.net
http://home.earthlink.net/~railro/
August 5th, 1999, 05:13 PM
Problems happening once a program is compiled in release, are almost ALWAYS because of initialization errors. That is, debug will automatically initialize your ints, etc. for you, release WILL NOT. I'm not sure what error you are seeing, but it could be an argument used by the .Mid() functions that is not being init'd and is ending up negative, or otherwise out-of-bounds. If you've already discounted this, let me know the error you are seeing (exception, etc.)
and I'll look at it again.
Good luck,
John
LHoffman
August 6th, 1999, 12:06 PM
Rail,
I saw the dup. CString as well. I got rid of of of them and my program still doesn't run in release mode. It's only when I open this certin file.
-LHoffman
Rail Jon Rogut
August 6th, 1999, 12:35 PM
If it's only happening with a certain file, then I'd suspect that there is a logic problem, and one of your variables being sent to Mid() is out of range -- Why don't you create these simple functions:
BOOL CYour2Doc::OpenLog(void)
{
if (!m_bMakeLogFile)
return FALSE;
CString szFName;
szFName = m_szOrigName.Left(m_szOrigName.GetLength() - 4) + ".log"; // Create a name for your log file
void CYour2Doc::CloseLog(void)
{
if (!m_bMakeLogFile)
return;
Flog.Close();
}
In your class' header add private member variables:
CStdioFile Flog;
BOOL m_bMakeLogFile;
Now in your code you can add some simple tracing which you can share with us...
What we need to know is what the values of the pertinent variables are around the call to Mid()... so when you start parsing this file (which causes your crash) make a call to OpenLog(), then at different places in the code add calls to WriteLogLine() with the variable value... for example, say you want to show the value for iresult, then add the code:
and when you're done parsing the file, make a call to CloseLog(). You can turn the logging on and off by setting the Boolean variable m_bMakeLogFile to TRUE or FALSE before you start parsing the file (in the class' constructor would be a good place to set this value).
When you've run the program and created a LOG file with a) the original unparsed file string, b) all the parsed strings and c) the variables and their values... email me a copy of the LOG file and the complete parsing function and its header file and I'll see if I can find your problem.
Rail
Recording Engineer/Software Developer
Rail Jon Rogut Software
railro@earthlink.net
http://home.earthlink.net/~railro/
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.