forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

fread weirdness with larger files

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Sat Dec 31, 2005 7:36 pm    Post subject: fread weirdness with larger files Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Sat Dec 31, 2005 8:31 pm    Post subject: Reply with quote

This may actually be a memory card corruption problem for me only - copying files onto the PSP via USB in a different order moves the problem to a different file.

On some files the PSP locks up completely.
Back to top
View user's profile Send private message Visit poster's website
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Sun Jan 01, 2006 2:18 am    Post subject: Reply with quote

Have the PSP do a format on the memory stick and give it another go

I have had VERY strange problems with a memory stick that have been solved this way, due to corruption.
Back to top
View user's profile Send private message AIM Address MSN Messenger
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Sun Jan 01, 2006 2:43 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Sun Jan 01, 2006 2:53 am    Post subject: Reply with quote

The PSP is really... strange... in the way it handles file IO.

For instance, when doing any disk IO you can pass in a 'repeat' factor that says how many times to retry something, because it doesnt always work.

So, I say you call it until it does what you want. But thats just me :)
Back to top
View user's profile Send private message AIM Address MSN Messenger
av



Joined: 01 Jan 2006
Posts: 7

PostPosted: Tue Jan 03, 2006 9:25 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Wed Jan 04, 2006 12:12 am    Post subject: Reply with quote

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.

Careful there - we don't see reports of anything breaking at -O2. Can you submit a valid repro for the hang?

A lot of time folks want to blame the compiler when they see weirdness caused by other bugs in their software.
Back to top
View user's profile Send private message
av



Joined: 01 Jan 2006
Posts: 7

PostPosted: Wed Jan 04, 2006 3:10 pm    Post subject: Reply with quote

mrbrown wrote:
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.

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.
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Wed Jan 04, 2006 3:57 pm    Post subject: Reply with quote

Looks more like a stack overflow/corruption.
Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Wed Jan 04, 2006 4:20 pm    Post subject: Reply with quote

av wrote:
it's a pretty large code base with a full game level worth of data. So submitting a repro isn't possible.

If you can't give us a way to reproduce this "compiler bug", I'm afraid you're going to have no luck convincing any of us that it exists.
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Wed Jan 04, 2006 5:24 pm    Post subject: Reply with quote

the fact that it works on windows isnt really proof either, windows can be very forgiving when it comes to broken code (how else would it even boot? :=D)
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group