RE: Program crashes when executed normally, but runs w/o trouble in the Debugger
RE: Program crashes when executed normally, but runs w/o trouble in the Debugger
- Subject: RE: Program crashes when executed normally, but runs w/o trouble in the Debugger
- From: "Lorance, Ted" <email@hidden>
- Date: Fri, 1 Jul 2005 11:09:13 -0700
- Thread-topic: Program crashes when executed normally, but runs w/o trouble in the Debugger
I appreciate everyone's suggestions, and I have implemented some (see below). However, it doesn't explain to me why the program works differently in the Debugger - and the situation has become even more inexplicable than before. With the alterations reproduced below, the program now functions completely normally even in the Performance Tools (which were previously causing the same crash as trying to load the datafile from normal execution). However, now when the program is run normally, it decides that the working directory is "/" instead of the correct value, and fails to load the file. It does not crash - the error trap worked fine - but it will not load the file, since the directory is wrong.
I was willing to believe that the Debugger was somehow altering the program's perception of its location, but this latest development still baffles me. If I knew why I was getting different results from the different systems, I could probably solve this on my own.
Any suggestions are appreciated.
Thanks,
Dr. Ted Lorance
New code:
char *buffer;
char *ptr;
char localBuffer[60];
FILE * in_file;
Boolean success;
long size;
size = pathconf(".", _PC_PATH_MAX);
if ((buffer = (char *)malloc((size_t)size)) != NULL)
{
ptr = getcwd(buffer, (size_t)size);
printf ("Current working directory is: %s\n",buffer);
}
err = GetControlByID (window, &kFileName, &cr_FileName);
require_noerr_quiet (err, CantGetControl);
err = GetControlData (cr_FileName, 0, kControlEditTextCFStringTag, sizeof(CFStringRef), &FileName_text, NULL);
require_noerr (err, CantGetControlData);
success = CFStringGetCString(FileName_text, localBuffer, 40, kCFStringEncodingMacRoman);
printf("%s\n",localBuffer);
strcat(buffer,"/\0");
printf("%s\n",buffer);
strcat(buffer,localBuffer);
printf("%s\n",buffer);
in_file = fopen(buffer,"rt");
if (in_file==NULL)
{
printf("File not found.\n");
return err;
}
else
{
printf("File found. All is well. Nothing to see here.\n");
}
Console log when running the program from the Debugger or Performance Tools:
Current working directory is: /Programming/XCode_Projects/Grapher
pCNBnBr_TAA_BuN_THA.KIN
/Programming/XCode_Projects/Grapher/
/Programming/XCode_Projects/Grapher/pCNBnBr_TAA_BuN_THA.KIN
File found. All is well. Nothing to see here.
Console log when running the program normally:
Current working directory is: /
pCNBnBr_TAA_BuN_THA.KIN
//
//pCNBnBr_TAA_BuN_THA.KIN
File not found.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden