I have some code that seems to crash when the function returns. I lack the knowledge to debug it. Can some one suggest why my code dies once the function dirList() returns?
If I remember rightly (I'm posting from work without much access to reference material) you need to initialise the "size" member of the dirinfo structure. It doesn't do any harm to memset the whole thing to zero, either.
I seem to recall people posting previous problems with the sceIoDread functions when using a dirinfo structure on the stack - you might have more joy using it off the stack - but I suspect that those are all related to not initialising ".size".
This same principle, of initialising the "size" member, applies to many other functions in the API, too.
EDIT: Forgot to mention why I think this causes the crash. If you haven't set up the size of the on-stack structure, then you're wide open to stack overflow which could corrupt the on-stack return address.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
Fanjita, unfortunately there isn't actually any size member in sceIoDirEntry, well there is but it is the size of the file ;) It just seems to be a bug in the MS driver as it works fine on all other devices such as flash and umd. ronniebeck I would just suggest setting the stack SceIoDirent variable to static and it at least shouldn't crash. Of course whether this is storing up trouble for later I wouldn't like to speculate :)
the solution i've found is place a static global sceIoDirEntry variable and call sceIoDread always and only with this variable (all *seems* stable now :)
otherwise it badly crash, not only with sceIoDirEntry on the stack but even if you malloc an array of sceIoDirEntry in the heap
In general, I'd recommend using newlib functions when possible, rather than calling Sce* directly, because in many cases we've already identified and worked around these sorts of quirks. In this case, opendir/readdir was fixed here.