Welcome! Log In Create A New Profile

Advanced

libfat 1.0.2 fopen methode fails sometimes?

Posted by wplaat 
libfat 1.0.2 fopen methode fails sometimes?
December 25, 2008 02:20PM
Hi everybody,

I am facing the following problem with the new libfat 1.0.2 library.

For some unknown reason sometimes a file (highscore.xml) stored on the SD(HC) card is not found during start up of my game. The previous version of libfat did not have this problem. Do anybody know a solution for this issue.

Sample code

void loadHighScoreFile(char* filename)
{
int i;
FILE *fp;
mxml_node_t *tree=NULL;
mxml_node_t *data=NULL;
const char *tmp;
char temp[100];

/*Load our xml file! */
fp = fopen(filename, "r");
if (fp!=NULL)
{
tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
fclose(fp);

for(i=0; i<=MAX_LEVEL; i++)
{
sprintf(temp, "level%d", i);
data = mxmlFindElement(tree, tree, temp, NULL, NULL, MXML_DESCEND);

tmp=mxmlElementGetAttr(data,"localTime");
if (tmp!=NULL) highscores.localTime=atoi(tmp); else highscores.localTime=0;

tmp=mxmlElementGetAttr(data,"levelTime");
if (tmp!=NULL) highscores.levelTime=atoi(tmp); else highscores.levelTime=0;

tmp=mxmlElementGetAttr(data,"player1Score");
if (tmp!=NULL) highscores.player1Score=atoi(tmp); else highscores.player1Score=0;

tmp=mxmlElementGetAttr(data,"player2Score");
if (tmp!=NULL) highscores.player2Score=atoi(tmp); else highscores.player2Score=0;
}
}
else
{
// If file not found, create empty highscore list.
for(i=0; i<=MAX_LEVEL; i++)
{
highscores.localTime=0;
highscores.levelTime=0;
highscores.player1Score=0;
highscores.player2Score=0;
}
}
mxmlDelete(data);
mxmlDelete(tree);
}


wplaat



Edited 1 time(s). Last edit at 12/25/2008 02:23PM by wplaat.
Re: libfat 1.0.2 fopen methode fails sometimes?
December 25, 2008 04:25PM
You're using the mxml library right?

I noticed similiar problems in libwiisprite and I fixed them using a more specific directory. This is because libfats default directory is no longer the folder your apps boot.dol is in.

Ex: data/fileiwanted.extension had to be changed to /apps/folderformyapp/data/fileiwanted.extension

Hope that helps.



Edited 1 time(s). Last edit at 12/25/2008 04:28PM by Arikado.
Re: libfat 1.0.2 fopen methode fails sometimes?
December 28, 2008 06:35PM
I don't have a solution, but I do have a debugging suggestion. Since fopen() can fail for multiple reasons, I'd check what's in 'errno' to find what the exact error is. I'd add something like this when you check fp for NULL:
#include <errno.h>
...
if (fp == NULL) {
  fprintf(stderr, "ERROR: %s\n", strerror(errno));
}
Re: libfat 1.0.2 fopen methode fails sometimes?
January 03, 2009 10:58PM
Hi Everybody,

I added now the complet path (as mention by Arikado) and it is working stable. Relative paths do not work anymore stable with libfat 1.0.2 is my conclusion.

Happy New Year!

wplaat
Re: libfat 1.0.2 fopen methode fails sometimes?
January 04, 2009 04:21AM
I really hope this will be remedied soon.
Sorry, only registered users may post in this forum.

Click here to login