| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 3:00 am Post subject: fopen problem (works in psplink) |
|
|
Hi folks,
I have this wierd error which only occurs when I run the game from my psp and not through PSPLink.
The problem is that fopen in this piece of code:
| Code: |
char ReadBuffer[256];
char sBuffer[256];
getcwd(ReadBuffer,100);
sprintf(sBuffer, "%s/Races/%s",ReadBuffer, race);
if((f = fopen(sBuffer,"rb")) != NULL) {
... }
else { displayerrr("fopen fails..."); }
|
in psplink it does not return NULL but when I run it just in the psp XMB menu in eboot form then it displays fopen fails...
now I have encountered such a problem in the past with the analog stick and in that case I forgot to include the initialisation of the analog stick and psplink did that automaticly.
This time I have allready used fopen to load up player data and that works because it just shows the info but later on when I load some other file it returns NULL as stated above.
any ideas ?
PS I have check the full path stored in sBuffer to see if that one was correct and it is correct. the file also exists otherwise it would not load up through psplink i guess.
EDIT:: I have already opened the file before that so the file is not faulty also :s it is really strange :s _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 6:15 am Post subject: |
|
|
Without psplink .. you're putting your file where is the eboot ?
maybe a silly question .. but psplink read from your computer directory ... and the standalone EBOOT from your MS ... :) (if you work with a relative path) |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 6:35 am Post subject: |
|
|
Hi,
well as you can see in the code I construct the sBuffer from the currentworkingdir then /Races/ and then the race name.
printing out this sbuffer right before the fopen creates:
ms0:/PSP/GAME150/RAZE/Races/Apple circuit.rac
and that is exactly where the file is.
here is a copy of browsing it with windows (copied from the file explorer)
M:\PSP\GAME150\RAZE\Races
and the file
Apple circuit.rac
so that should not be the problem.
the file properties is only "a" (archive)
so unless I miss something that should be correct since I don't use relative paths _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 6:37 am Post subject: |
|
|
have you tried to remove the blank space in the race name .... (and change it everywhere according to it) ?
... |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 7:01 am Post subject: |
|
|
Hi well I open the file using the same functions in the mainmenu. It reads out the file to display a small map of the racetrack. after that I choose a car and then it loads the file again to load up all the objects and stuff.
So opening the file with space works fine. I have deleted the space just to be sure and it did not matter.
here is the code of the opening before the crash:
| Code: | bool MainMenu::LoadLevelLayout() {
int x, y, i;
FILE *f;
char sBuffer[256];
char ReadBuffer[256];
sprintf(sBuffer, "Races/%s", Races[RaceItem]);
for(x=0;x<16;x++)
for(y=0;y<10;y++)
trackLayout[x][y] = 0;
if((f = fopen(sBuffer,"rb")) != NULL) {
// parse the info.
// read version
for(i = 0; i<7; i++)
fgets(ReadBuffer, 256, f);
// read the dimensions
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+2),"%d",&x );
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+2),"%d",&y );
if(x>16) { fclose(f); return false; }
if(y>10) { fclose(f); return false; }
for(i=0;i<y;i++){
fgets(ReadBuffer, 256, f);
// readbuffer has now one row of the field.
for(unsigned int j=0;j<strlen(ReadBuffer)-1;j++){
//trackLayout[j][i] = 1;
switch(ReadBuffer[j]){
case '1':
trackLayout[j][i] = 1;
break;
case '2':
trackLayout[j][i] = 2;
break;
case '3':
trackLayout[j][i] = 3;
break;
case '4':
trackLayout[j][i] = 4;
break;
case '5':
trackLayout[j][i] = 5;
break;
case '6':
trackLayout[j][i] = 6;
break;
default:
trackLayout[j][i] = 0;
break;
}
}
//
}
// done so close
fclose(f);
}
return true;
}; |
_________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 7:18 am Post subject: |
|
|
hummm can we have an example of your race file ?...
it seems that your format version take 7 lines !!??!! (fgets stops when a '\n' is found)
... why don't you do a
while(fgets(....))
{
//parsing with sscanf ...
...
}
? |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 7:28 am Post subject: |
|
|
Hiya,
well the last code that I sended works fine, it opens the file reads out the data and then shows the layout, the first seven line have info only needed for the actual build of the track so not needed in that function and thus skipped.
I showed that function because maybe I did not close the correctly or something it is just very strange why the file is opened at that moment and then 2 menuscreen further it crashes :s _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 7:34 am Post subject: |
|
|
Why do you add "2" on the readbuffer ? ...
| Code: | | sscanf((ReadBuffer+2),"%d",&x ); |
Your code looks strange for me :P |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 7:40 am Post subject: |
|
|
because those lines start with:
x=
y=
but that code is not the problem i guess, this is the code which states the errormessage:
| Code: | int SingleRace::ParseSingleRace(const char* race) {
FILE *f;
char ReadBuffer[256];
char sBuffer[256];
getcwd(ReadBuffer,100);
sprintf(sBuffer, "%s/Races/%s",ReadBuffer, race);
//DebugTools::PrintTextLoop(sBuffer);
//DebugTools::PrintTextLoop("Het komt nog tot hiero \n");
if((f = fopen(sBuffer,"rb")) != NULL) {
// parse the info.
// read version
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+8),"%d",&version);
// read difficulty
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+11),"%d",&difficulty);
// read difficulty
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+11),"%d",&maxplayers);
// start reading x and y start(finish).
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+8),"%d",&startPos.y );
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+8),"%d",&startPos.x );
// start reading x and y halfway.
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+9),"%d",&halfwayPos.y );
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+9),"%d",&halfwayPos.x );
// read the dimensions
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+2),"%d",&dimension.x );
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+2),"%d",&dimension.y );
// create the 2D array
Track = new std::vector<std::vector<TrackPart*>*>;
//DebugTools::PrintTextLoop("Het komt nog tot hiero \n");
for(int i=0;i<dimension.y;i++){
fgets(ReadBuffer, 256, f);
// readbuffer has now one row of the field.
//create the vector for 2d array
TrackLine = new std::vector<TrackPart*>;
for(unsigned int j=0;j<strlen(ReadBuffer);j++){
DebugTools::PrintText(&ReadBuffer[j]);
switch(ReadBuffer[j]){
case '1':
//straight1.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(1);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartStraight2);
tmpPart->setWaypoints(1);
TrackLine->push_back(tmpPart);
break;
case '2':
//straight2.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(2);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartStraight1);
tmpPart->setWaypoints(2);
TrackLine->push_back(tmpPart);
break;
case '3':
//corner1.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(3);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartCorner4);
tmpPart->setWaypoints(3);
TrackLine->push_back(tmpPart);
break;
case '4':
//corner2.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(4);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartCorner1);
tmpPart->setWaypoints(4);
TrackLine->push_back(tmpPart);
break;
case '5':
//corner3.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(5);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartCorner2);
tmpPart->setWaypoints(5);
TrackLine->push_back(tmpPart);
break;
case '6':
//corner4.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(6);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartCorner3);
tmpPart->setWaypoints(6);
TrackLine->push_back(tmpPart);
break;
case ' ':
TrackLine->push_back(NULL);
break;
}
}
//save the array in the 2d array
Track->push_back(TrackLine);
}
// done so close
fclose(f);
}
else {
DebugTools::PrintTextLoop("Error reading the race \n");
}
return 0;
} |
maybe there is something not correct ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 7:49 am Post subject: |
|
|
try to break your code into small parts and checks each part l.. part by part.. displaying some variable status etc... ... and put some pspdebugprintf to display the debug on the PSP
and for reading files ...
| Code: | | sscanf(ReadBuffer,"y=%d",&y); |
should be better (for example). because in your case, if "y=" is set before the "x=" in the file ... your parsing will be wrong ... |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 7:54 am Post subject: |
|
|
well the problem is that it output this line:
DebugTools::PrintTextLoop("Error reading the race \n");
which means the fopen returns NULL
I just don't know why that happens normally but in PSPlink not.
the sBuffer is filled in correctly. _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 8:04 am Post subject: |
|
|
| very strange ... can you get the strlen of sBuffer and be sure that there is no '\n' or something else ? maybe there is a blank space before or after you "real" sBuffer ... the fopen method seems to be called perfectly ... so if you're sure that the file is at the correct place and sBuffer doesn't hidden any specific unwanted char .... i can only recommend you , if you are in C++, to use <string> lib (with std::ifstream for files) ... |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 8:26 am Post subject: |
|
|
well there is no \n because my debugger adds one and when it loop prints it there is now empty line which was the case with two \n
the length is 44 which is the exact total of character in sBuffer.
the only thing that comes to my mind is that the file is open or something :s _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 9:28 am Post subject: |
|
|
Hmmm I have now set the path and filename hardcoded and both the old way i did and now with strings: | Code: | std::ifstream input;
std::string line, file;
std::string::size_type loc;
file = "ms0:/PSP/GAME150/RAZE/Races/C Circuit.rac";
input.open(file.c_str());
getline(input,line);
DebugTools::PrintTextLoop(line.c_str());
sscanf(line.c_str(),"version=%d",&version);
input.close(); |
It does not show any line....
so this means that 1.) the path and filename is incorrect or 2.) the file is already opened.
well 1 I have hardcoded it and then it also does not work so it should be 2.
However I really do not know where I open the file and do not close it :s
it there a 3 ??????? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 9:48 am Post subject: |
|
|
does the same with a file at the root of the MS ? ...
seems very very strange ... hard reset your psp :D |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 6:36 pm Post subject: |
|
|
well I open a lot of files previous to this, thats the strange thing even the same file.
If a file is already open what does the fopen?
is there a way to see if the file is open if you don'T have the filepointer structure ?? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 8:12 pm Post subject: |
|
|
the only way of keep THIS file opened is to forget to close it ... is this file is opened before in your code ?
The psp doesn't open files itself "for fun" :Ptry maybe to recreate your race file .... copy/paste his content to a new file. |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Aug 07, 2007 8:25 pm Post subject: |
|
|
the only time it is opened is in that code i pasted in my post:
| Quote: | | Code: | bool MainMenu::LoadLevelLayout() {
int x, y, i;
FILE *f;
char sBuffer[256];
char ReadBuffer[256];
sprintf(sBuffer, "Races/%s", Races[RaceItem]);
for(x=0;x<16;x++)
for(y=0;y<10;y++)
trackLayout[x][y] = 0;
if((f = fopen(sBuffer,"rb")) != NULL) {
// parse the info.
// read version
for(i = 0; i<7; i++)
fgets(ReadBuffer, 256, f);
// read the dimensions
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+2),"%d",&x );
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+2),"%d",&y );
if(x>16) { fclose(f); return false; }
if(y>10) { fclose(f); return false; }
for(i=0;i<y;i++){
fgets(ReadBuffer, 256, f);
// readbuffer has now one row of the field.
for(unsigned int j=0;j<strlen(ReadBuffer)-1;j++){
//trackLayout[j][i] = 1;
switch(ReadBuffer[j]){
case '1':
trackLayout[j][i] = 1;
break;
case '2':
trackLayout[j][i] = 2;
break;
case '3':
trackLayout[j][i] = 3;
break;
case '4':
trackLayout[j][i] = 4;
break;
case '5':
trackLayout[j][i] = 5;
break;
case '6':
trackLayout[j][i] = 6;
break;
default:
trackLayout[j][i] = 0;
break;
}
}
//
}
// done so close
fclose(f);
}
return true;
}; |
|
but to my knowledge i close it here fine. _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 8:45 pm Post subject: |
|
|
instead of :
try
declare your FILE ressource like this everywhere :) |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
|
| Back to top |
|
 |
MikeMax
Joined: 05 Apr 2007 Posts: 5
|
Posted: Tue Aug 07, 2007 11:21 pm Post subject: |
|
|
it seems that your problem is very strange as KoalaDB said ... good luck ... _________________ MikeMax,
Lead developper
Vertex Origin Studios
www.VertexOrigin.net |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Tue Aug 07, 2007 11:24 pm Post subject: |
|
|
| Ghoti wrote: | that also does not work :(
I will check the paths and stuff again :s |
Yes check check check ... i don't see any other solution ... :( |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Aug 08, 2007 12:38 am Post subject: |
|
|
well I now use:
| Code: |
sprintf(sBuffer, "ms0:/a.rac");
if((f = fopen(sBuffer,"rb")) != NULL) {
...
}
else{
debug out error message
} |
that is a file in the root; I never opened it before that moment and I still get the error message :s
EDIT:::::
I have changed the a.rac into the name of a file already in the root, ss.png and I can't open that one either...
it seems that at that moment I can't read anything from the memorystick or something is there some switch or something which I can have used by acident ?? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Aug 08, 2007 1:23 am Post subject: |
|
|
well I have tried the third option, using the pspsceiopen function:
| Code: | int fdout = sceIoOpen("ms0:/a.rac", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_APPEND, 0777);
if(fdout < 0)
{
char s[200];
sprintf(s, "Openen is niet gelukt. Err: %d", fdout);
DebugTools::PrintTextLoop(s);
} |
this also does not work but now it returns some error value, maybe someone knows what the error value means?
Err = -2147418088 _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
crazyc
Joined: 17 Jun 2005 Posts: 410
|
Posted: Wed Aug 08, 2007 1:57 am Post subject: |
|
|
| Ghoti wrote: | | Err = -2147418088 |
-2147418088 == 0x80010018
0x80010018 is the same as the 0x18 posix errno or
| Code: | EMFILE 24 /* Too many open files */
|
|
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Wed Aug 08, 2007 3:11 am Post subject: |
|
|
| Yes that old chestnut ;) Basically for what ever reason the memory stick driver is quite limited in the number of files it can open, however the psplink host driver can open far more. Cant remember off hand but it is something like 16 files vs 64 or so. I guess if I was that bothered I could add an emulation mode to the host driver like I do to enable case insensitivity but I doubt it is worthwhile :) |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Aug 08, 2007 3:36 am Post subject: |
|
|
hmmm that not so good :s do you means 16 files open at one moment or you can't open more then 16 files even when you have closed them ? because at that moment there are not many files open... only that file actually.
so when I do not open all the other files it should be opened ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Wed Aug 08, 2007 3:40 am Post subject: |
|
|
| By the way, after your "fopen" fails, you should always check "errno" to see the cause; it should have contained EMFILE in this case. If it doesn't, it's a bug and I can look into it. perror and strerror are also useful functions. |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Aug 08, 2007 3:47 am Post subject: |
|
|
Well Tyranid you are my hero, it was exactly that, one of my classes opened a file but did not close it. Now it is closed and it does not crash anymore !!! :D
@jimparis: thank you for that info, did not know of the "errno" that was the reason why I used the native psp open function because that returned an error number. I will also look into perror and strerror, it sound helpfull! thanks _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
KoalaDB
Joined: 06 Aug 2007 Posts: 20
|
Posted: Wed Aug 08, 2007 6:00 pm Post subject: |
|
|
| Ghoti wrote: | | one of my classes opened a file but did not close it. Now it is closed and it does not crash anymore !!! :D |
... The next time when it is asked to check ... please check :p |
|
| Back to top |
|
 |
|