Author Topic: Saving and loading in 2.4  (Read 4670 times)

Offline Elite

  • Bot Overlord
  • ****
  • Posts: 532
    • View Profile
Saving and loading in 2.4
« on: May 03, 2006, 05:22:29 PM »
My sim won't load. You can get it in the 'shortest evobot' topic.

I think Testlund found that his save got courupted too ... this needs to be adressed

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Saving and loading in 2.4
« Reply #1 on: May 03, 2006, 05:53:31 PM »
Well I already experienced this quite often, but I am not sure if this is limited to 2.4 so I was silent about it.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Saving and loading in 2.4
« Reply #2 on: May 03, 2006, 11:00:27 PM »
I've tracked this down.  Believe it or not, it's another overflow bug.  It's been in the code for a long time and probably exists in 2.37.6.

When you save a sim, it saves all the bots in the sim including for each, the textual descriptions of all the mutations that have occurred along that bot's ancestaral line.   The way the simulation save/load code works for varaible length things like this is that it first saves the length of the thing to the file and then saves the thing itself.  This way, when it's read back in from the saved file, the length can be read in first and used to allocate the right amount of memory for reading back in the actual data.

Well, wouldn't you know it, the length of the mutation details is converted to an Integer before it is saved to the sim file.  This means that if the length of the string exceeds 2^15 bytes, the number saved to the file will be negative!!!!!  When the code attempts to load the sim file, it reads this negative number and attempts to allocate a negative sized string, which is what generates the illegal procedure call error.

So, basically, any sim file containing bots with large numbers of mutations will fail to load.

I will fix this in a backward compatable way in 2.42.4 which I will try to drop quickly, say by this weekend.
« Last Edit: May 03, 2006, 11:12:46 PM by EricL »
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Saving and loading in 2.4
« Reply #3 on: May 04, 2006, 12:06:34 AM »
A "save sim fixer" would be nice too.  I don't want to lose some of my corrupted saved sims. :/

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Saving and loading in 2.4
« Reply #4 on: May 04, 2006, 12:15:30 AM »
Quote from: Numsgil
A "save sim fixer" would be nice too.  I don't want to lose some of my corrupted saved sims. :/
My goal is for 2.42.4 to be able to read older sim files with this specific corruption and save them correctly.  So 2.42.4 will hopefully be a "saved sim fixer" for this specific issue at least.
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Saving and loading in 2.4
« Reply #5 on: May 04, 2006, 12:27:21 AM »
It seems to me possible that you should be able to read in the mutation details without referencing the string length if your save sim reader is smart enough.  Especially since most mutation details are quite regularly syntaxed.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Saving and loading in 2.4
« Reply #6 on: May 04, 2006, 01:59:45 AM »
I looked at parsing the strings directly.  It's quite a bit of work to do it right as different mutation types use different initial strings.  What I've done instead isn't as good, but its probably good enough and saves me a lot of time and testing.

Saving sims:

If the length of the mutation details are < 2^15-1, things are the same.  The length is stored as an Int, older versions will read the new files just fine.
If the length of the mutation details is >= 2^15-1 then I use a magic length number of 1 (the mutation details will never naturally have length 1) to signal to the read routine that the real length is stored immediatly following as a Long.  If an older version trys to read such a file, it should still load, but the mutation details will be lost and everything following in the file for that bot will load incorrectly including the mutation settings.  But it will load.

Reading Sims:
  If the length is negative, we can assume it's a pre 2.42.4 file with lots of mutations.  I read 2^15 -1 bytes of mutation drtails, then bail, skipping the rest of the bot.  The sim will load, but as above, some things for that bot will be random valued.
  If the length is postive but not 1, could be old or new file, just read that and keep going.  All is well.
  If the length is 1, its a new file with lots of mutations.  Read the actual length as a Long then read the complete Mutation details.

So, in short, new saves preserve all mutation details even if they exceed 2^15-1 bytes.  2.42.4 and forward lets you save and load bot mutation details of any length.  New files can be read by older versions, but sims with tons of mutations may load random values for some bots if loaded by older versions.   But they will load.  No more negative lengths!  Old sims saved by older versions with tons of mutations will load in 2.42.4, but some bot values may be random.
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Saving and loading in 2.4
« Reply #7 on: May 04, 2006, 12:40:30 PM »
Nice, that was an elusive bug that seemed to pop up from time to time and I could never figure out why.

Offline Evitan

  • Bot Neophyte
  • *
  • Posts: 5
    • View Profile
Saving and loading in 2.4
« Reply #8 on: May 13, 2006, 01:38:48 AM »
I get the same problem now. Sim is at 6.8 Million cylces and I can't go any higher without getting "bad or invalid procedure call" when loading.

Maybe an option button while saving a sim to delete mutation history? Interesting for very long evo sims.

Maybe I should buy a better computer....

I'll wait untill the next version to continu the sim.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Saving and loading in 2.4
« Reply #9 on: May 13, 2006, 09:47:28 AM »
I think this has been fixed in 2.42.4