fread weirdness with larger files
fread weirdness with larger files
Hello,
I'm attempting to port a game to PSP, and for some reason, the fread function has problems with large files. With a file on the memory stick which is around 2MB in size, the following call:
FILE* file = fopen("./myfile.dat", "rb");
int read = fread(buffer, 1, 65536, file);
returns 16384 instead of 65536. Subsequent calls return 0. Has anyone seen this problem before?
I'm not sure where to look for the source for fread, apologies if I'm doing something stupid...
Peter
I'm attempting to port a game to PSP, and for some reason, the fread function has problems with large files. With a file on the memory stick which is around 2MB in size, the following call:
FILE* file = fopen("./myfile.dat", "rb");
int read = fread(buffer, 1, 65536, file);
returns 16384 instead of 65536. Subsequent calls return 0. Has anyone seen this problem before?
I'm not sure where to look for the source for fread, apologies if I'm doing something stupid...
Peter
Thanks for the tip. I tried it out earlier (backing up my game saves, formatting the card, then restoring the saves) and it seems to have helped.
I still get the occasional problem though - e.g. files refusing to delete from the memory stick - I think my memory stick is knackered...
Thanks again for the advice.
I still get the occasional problem though - e.g. files refusing to delete from the memory stick - I think my memory stick is knackered...
Thanks again for the advice.
I just spent 4 hours working through other file read related hang problems. You may want to try changing your Makefile to compile with -O1 instead of -O2. -O1 will do less optimization. However, -O2 seems to cause my app to hang the PSP if I change a line of code from time to time (I think gcc's optimizations are a little busted on the PSP). With -O1 everything seems to work as expected.
Careful there - we don't see reports of anything breaking at -O2. Can you submit a valid repro for the hang?av wrote:I just spent 4 hours working through other file read related hang problems. You may want to try changing your Makefile to compile with -O1 instead of -O2. -O1 will do less optimization. However, -O2 seems to cause my app to hang the PSP if I change a line of code from time to time (I think gcc's optimizations are a little busted on the PSP). With -O1 everything seems to work as expected.
A lot of time folks want to blame the compiler when they see weirdness caused by other bugs in their software.
Unfortunately, while I can definitely repro it 100% of the time, it's in a code base that belongs to my company...and it's a pretty large code base with a full game level worth of data. So submitting a repro isn't possible.mrbrown wrote:A lot of time folks want to blame the compiler when they see weirdness caused by other bugs in their software.
The code has run fine for months in Windows for D3D. I've run BoundsChecker on it many, many times and while BoundsChecker isn't perfect, I've had no problems in the Windows build. The PSP build with -O1 runs without problems like the Windows build...the -O2 build hangs whenever I make completely safe changes like the following:
If I compile a for loop with a variable like:
for (int32 i=0; i<numLoops; i++)
That works fine. But when I change it to a constant:
for (int32 i=0; i<2; i++)
This hangs on the PSP right after the PSP loading screen fades away. Recompiling with -O1 causes it to work perfectly. Definitely looks like a compiler bug to me. This won't happen with all for loops, just certain ones that cause the compiler to crap the bed.
Thanks.