In the Card_Init function it sets the flag card_inited = 1; once the card is initiated, however the flag is never reset.
This cause problems with applications that list a directory and then need to save, erase. This is because when listing a directory you would init with a NULL gamecode and country, so after this any operation which needs a gamecode and country will fail.
Putting card_inited = 0; once Card_Unmount is called would work fine.
This should fix any bugs in current memory card applications like MCbackup also.
I noticed in older versions of libogc you had a reinit function but was removed in later releases.
thanks
libogc: Card Init / Reinit Problem
-
- Site Admin
- Posts: 1986
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: libogc: Card Init / Reinit Problem
The unmount solution seems good to me, I've changed that in CVS now. Thanks.
Re: libogc: Card Init / Reinit Problem
Here some reflexion about the low-level SDCARD support:
A problem occurs when:
1/ you first try to acces an unrecognized device (memcard or empty sd adapter) in one of the MC slot
--> you are not able to access ANY slots anymore, even if proper sdcard is present in another slot
2/ you swap between sdcards (remove then reinsert) or more generally, insert a sdcard after the slot has already been acceeded, successfully or not (see above)
--> the card IO is not reinitialized properly and some errors may occur
Now, here's what I found by analysing code in libogc:
Here is an easy & quick solution to solve the problem, tested and approved
I verified it didn't impact anything else
In card_initIO:
A problem occurs when:
1/ you first try to acces an unrecognized device (memcard or empty sd adapter) in one of the MC slot
--> you are not able to access ANY slots anymore, even if proper sdcard is present in another slot
2/ you swap between sdcards (remove then reinsert) or more generally, insert a sdcard after the slot has already been acceeded, successfully or not (see above)
--> the card IO is not reinitialized properly and some errors may occur
Now, here's what I found by analysing code in libogc:
1/ there is a static variable in the cart library, _ioRetryCnt, that is used to hold the number of retries when you try to mount a sdcard in a MC slot through sd-adapter.
2/ there is also a variable __ioFlag for each slot that hold teh current status of the card in a slot: each time you try to access SD (read sectors,etc), if the flag is set as NOT INITIALIZED, the function card_initIO is called and then, IF the retry counter is not at the maximal value, the function will try to initialize the card.
3/ Now, if there is a device inserted in the MC slot AND if this device is a memcard or an empty sd-adapter (in both cases, that means that no sdcard is found), the retry counter will be incremented in loop in the function card_initIO. When the counter is 5, the function exit with an error code.
3/ the only way to reset this counter is to call the function card_initIODefault (this is called by SDCARD_Init)
4/ this counter is shared by BOTH slots, which mean that once it reached the max value (see above), you won't be able to initialize any of the 2 slots again, even if a sdcard is properly inserted then.
Now :
. calling SDCARD_Init each time you want to access a slot does not help because there is also an internal flag (sdcard_inited) that prevent from initializating everything twice.
. a better solution could be to call the functions card_initIODefault() each time you are going to access the SDCARD (this could be interesting to swap between sdcards without any problems). But the problem there is that this function also initialize a LWP queue that should be first closed (otherwise, it wil allocate a new queue in memory each time you access sdcard)
Here is an easy & quick solution to solve the problem, tested and approved
I verified it didn't impact anything else
In card_initIO:
if(_ioRetryCnt>5)
{
_ioRetryCnt = 0;
return CARDIO_ERROR_IOERROR;
}
Who is online
Users browsing this forum: No registered users and 0 guests