Sorry, not stupid at all.
Char dbString[32];
Jim Morris wrote:
Stupid question but what is dbString defined as?
Javier Sedano wrote:
Hello friends,
my name is Javier Sedano, and I'm trying to develope a PalmOS
client for VGAPLANETS (a famous turn-based strategy game):
http://palmplanets.sourceforge.net/
You can download the source there, but it does not include the
problem I'm describing here.
I've been stuck for the whole day with a very strange problem.
Under some very special (and deterministic) circunstances VFSOpen()
returns -1, which acordingly to the documentation is not possible.
The following code fails:
Boolean p_OpenDataFile(const Char *file, FileRef *refFile){
Err err;
Char stringFile[MAXPATH];
StrPrintF(stringFile, "%s/%s", p_stringGame, file);
err = VFSFileOpen(p_volWinplan, stringFile, vfsModeRead, refFile);
// (1)
if (err == errNone) return true;
if (err != vfsErrFileNotFound) return false;
StrPrintF(stringFile, "%s/%s", p_stringWinplan, file);
err = VFSFileOpen(p_volWinplan, stringFile, vfsModeRead,
refFile); // (2)
if (err == errNone) return true;
return false; }
Boolean p_PlanetsLoad(UInt8 game, UInt8 player) {
[...]
if (!p_OpenDataFile("XYPLAN.DAT", &refFile)) // (1)
return false;
VFSFileClose(refFile);
if (!p_OpenDataFile("XYPLAN.DAT", &refFile)) // (2)
return false;
VFSFileClose(refFile);
StrPrintF(dbString, "Planets_%i_%i", game, player);
if (!p_OpenDataFile("XYPLAN.DAT", &refFile)) // (3)
return false; // (exits here)
VFSFileClose(refFile);
[...]
}
The first call to p_OpenDataFile() goes fine, as do the second
call (just to be sure that it was not a problem of the second call
failing).
The third call fails, so the "return false" is raise
Using the debugger to see why the hell is it failing, I see that,
in the third call, VFSFileOpen is returning -1, so obviously the
"if (err != vfsErrFileNotFound) return false;" line causes to return
false.
Am I sure that StrPrintF() line is they guilty for the error? Yes,
I am. If I comment StrPrintF(), the third p_OpenDataFile() goes fine,
but of course it crashes later, when dbString is needed ;-)
If I use "StrCopy(dbString, "Planets_1_10");" instead, it also fails.
If I change it to (notice that I've changed also the variable name):
dbS[0] = 'P';
dbS[1] = 'l';
dbS[2] = 'a';
dbS[3] = 'n';
dbS[4] = 'e';
dbS[5] = 't';
dbS[6] = 's';
dbS[7] = '_';
dbS[8] = '1';
dbS[9] = '_';
dbS[10] = '1';
dbS[11] = '0';
dbS[12] = 0;
... it also fails
Any idea?
What am I doing wrong?
I can find a workaround for this particular case, but I will find
the problem later...
Regards,
--
Javier Sedano Jarillo: [EMAIL PROTECTED]
Agora Systems S.A.
C/Velazquez, 46, 6ยบ derecha; E-28001 Madrid (Spain)
Tel.: +34 676 48 29 55; Fax.: +34 91 577 76 72
--------
Who searches the Truth, is in risk of finding it.
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/