I tried @btco's "PMEM TEST" cartridge on Chrome.
Upon the first reset of the cart, the PMEM didn't save (it resets to 0), but resetting the cart more saved the contents of the PMEM like it should. That's why you must reset the cart when it launches after the TIC-80 splash screen has played.
Yes, thats the weird thing. Also map and other stuff is reseting. Im talking about random generated and saved by sync() map.
I have noticed similar behaviour on native Windows builds. To my knowledge, resetting the cart with reset() doesn't fix the bug, but resetting from the ESC menu does. And this has to be performed every time TIC-80 is opened.
I'm suspecting the SAVEID doesn't get registered until a successful reset, and the default SAVEID is used instead.
So I spent quite some time trying to figure this out today but sadly I ran out of time, so I'm gonna continue tomorrow.
These are some things I found:
diff --git a/src/tic.c b/src/tic.c
index 41e48e2..6a10b59 100644
--- a/src/tic.c
+++ b/src/tic.c
@@ -1749,6 +1749,10 @@ static void updateSaveid(tic_mem* memory)
{
memset(memory->saveid, 0, sizeof memory->saveid);
const char* saveid = readMetatag(memory->cart.code.data, "saveid", tic_core_script_config(memory)->singleComment);
+
+ // saveid is only saved to memory after a reset from the menu
+ printf(saveid);
+
if(saveid)
{
strncpy(memory->saveid, saveid, TIC_SAVEID_SIZE-1);
updateSaveid function is called and the saveid is actually saved into memory. But still the persistent memory is not being read correctly. The only difference from a reset from lua and a reset from the menu is the call of setStudioMode:diff --git a/src/menu.c b/src/menu.c
index 3b3c68e..c67cd9e 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -47,6 +47,8 @@ static void resetGame(Menu* menu)
tic_api_reset(tic);
+ // that's the only difference when reseting from the menu compared
+ // to reseting with the API
setStudioMode(TIC_RUN_MODE);
}
@@ -523,4 +525,4 @@ void initMenu(Menu* menu, tic_mem* tic, FileSystem* fs)
},
.mode = MAIN_MENU_MODE,
};
-}
\ No newline at end of file
+}
Fixed here c9ac879.
Thanks.
Most helpful comment
So I spent quite some time trying to figure this out today but sadly I ran out of time, so I'm gonna continue tomorrow.
These are some things I found:
updateSaveidfunction is called and the saveid is actually saved into memory. But still the persistent memory is not being read correctly. The only difference from a reset from lua and a reset from the menu is the call ofsetStudioMode: