GP32 Random Smc Open Errors


Pirotic

Certified Guru
Joined
Feb 16, 2004
Messages
593
Hiya, my app is always opening, writing and closing files - weird thing is, no matter how often i check the code make sure its all fine, after i open a file 10 or so times it ends up erroring and failing to load, even if i leave a long pause between the load attempts.

it seems pretty random, but its almost as if, once its saved a total amount (in terms of size) it just dies on me :D

i've tried just running one little peice of code 10 times (with a 5 second pause inbetween) and indeed, it always crashs on the 11th run.. the code is

sprintf((char*)filename, "M%dS.DAT", map_settings.current_map);
if (GpFileCreate(filename, ALWAYS_CREATE, &h_file) != SM_OK)  MsgBox("Error creating M_S.DAT");
if (GpFileOpen(filename, OPEN_W, &h_file) != SM_OK) MsgBox("Error opening M_S.DAT");
if (GpFileWrite(h_file, save_settings, sizeof(unsigned short) * 4) != SM_OK) MsgBox("Error writing M_S.DAT");
if (GpFileClose(h_file) != SM_OK) MsgBox("Error closing M_S.DAT");

Any suggestions? should i GpFatInit when my app first loads, should i be calling it everytime i want to save or am i not closing the file correctly or something, its strange :p
 
From what I heard in the SMC defrag topic, repeatedly writing to the SMC is not good.

Anyway, I'm not an expert, but I think you should try putting a delay after each time you close the file. You might be overflowing a write buffer by writing to the SMC so much.
 
AH HA! I knew it wasnt just me!
See this topic:
http://www.gp32x.de/board/index.php?showtopic=8658

I brought up the VERY SAME ISSUE, and its exactally 10 times too!

I have noticed that it does it when reading OR writing to the file, so the issue about "Not writing many times to a SMC" is not applicable to this situation.

When I open a file, read from it, close it, 10 times, the 11th time (ALWAYS) fails.
 
Last edited by a moderator:
sounds like a nasty SDK glitch - did you manage to fix it in the end Akuma? or do you know any work-arounds :p

the gigas-editor may be dead before it even started if the GP32 cannot save more than 10 times :( i'll have to work on the PC one instead i suppose.

its not even a memory leak as i keep track of the ram free and used at every tick :p

can everybody instead comment in Akuma's thread from now on, and close this one - dont want to duplicate the same thing.
 
Ah, but your thread is on the front page while Akuma no Houkon's is well into history by now :)

GpDoom had a lot of gpsdk-related file problems, and I "mostly" got rid of them by using some other SMC access code. The problem with the other code is that the license is not GPL and now I've got to remove it again. I'm working on a SMC library replacement from scratch (and it will be GPL) but it's taking a LONG time so don't hold your breath :(

I did a huge amount of testing and was never able to find a pattern for the SMC problems with the SDK. It's certainly interesting that it happens every 10 times for you and Akuma no Houkon...
 
GpFatInit should only ever be called once, at the start of your proggy. To get around this bug that seems to be in the SDK, you could always use Mirko's :)

If not, then do like in BOR - shove everything in one file and just read from that.
 
Pirotic posted on Apr 19 2004 at 09:19 PM said:
Hiya, my app is always opening, writing and closing files - weird thing is, no matter how often i check the code make sure its all fine, after i open a file 10 or so times it ends up erroring and failing to load, even if i leave a long pause between the load attempts.

it seems pretty random, but its almost as if, once its saved a total amount (in terms of size) it just dies on me :D

i've tried just running one little peice of code 10 times (with a 5 second pause inbetween) and indeed, it always crashs on the 11th run.. the code is

sprintf((char*)filename, "M%dS.DAT", map_settings.current_map);
if (GpFileCreate(filename, ALWAYS_CREATE, &h_file) != SM_OK)  MsgBox("Error creating M_S.DAT");
if (GpFileOpen(filename, OPEN_W, &h_file) != SM_OK) MsgBox("Error opening M_S.DAT");
if (GpFileWrite(h_file, save_settings, sizeof(unsigned short) * 4) != SM_OK) MsgBox("Error writing M_S.DAT");
if (GpFileClose(h_file) != SM_OK) MsgBox("Error closing M_S.DAT");

Any suggestions? should i GpFatInit when my app first loads, should i be calling it everytime i want to save or am i not closing the file correctly or something, its strange :p
Afaik GpFileCreate() also opens the file when you create it. So checking your code you open the file twice but close only once. That might be the reason for your problems.
 
Last edited by a moderator:
seeing as most of you decided not to bother returning to the old thread (lol) -

i managed to fix it, i figured when i created the files it automatically opened them to, so my normal 'always create then open' routines would eventually lead to it buggering up, so now it only creates it if it has a problem opening it, and it seems to be fine (made a map today without a single bug, hurrah)

i think the cause of the bug may be you cannot have more than 10 files open at once or something similar, its not a RAM issue but could still be an SDK issue.

in the end i had to spend ages debugging, commenting out most of my code and figuring out where it was going wrong.
 
Pirotic posted on Apr 20 2004 at 10:23 AM said:
i managed to fix it, i figured when i created the files it automatically opened them to, so my normal 'always create then open' routines would

i think the cause of the bug may be you cannot have more than 10 files open at once or something similar, its not a RAM issue but could still be an SDK issue.
Like I said earlier.. file creation opens the file as well. Current SDk has a hardcoded limit (10 times) for a number of times you can open one file. So guys doing their own SDKs with that Samsung code base for SMC stuff could easily "tweak" that define or modify the file creation functions or even better embed that into opening function. <_<
 
Last edited by a moderator:
Back
Top