Error Writing To Save File

Describe your experience with the latest version of FreeOrion to help us improve it.

Moderator: Oberlus

Forum rules
Always mention the exact version of FreeOrion you are testing.

When reporting an issue regarding the AI, if possible provide the relevant AI log file and a save game file that demonstrates the issue.
Message
Author
knelson
Space Krill
Posts: 6
Joined: Tue Oct 20, 2015 10:51 pm

Error Writing To Save File

#1 Post by knelson »

I have been getting an error when the program tries to autosave. I noticed this happens after 290 turns or more. I am running the latest version. 4.5 build 2016-01-11.609936e. I was having the same issue with the previous version was hoping it was fixed in this release.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Error Writing To Save File

#2 Post by Geoff the Medio »

Edit: removed unnecessary discussion of XML vs. binary save settings /Edit

If you have a save that reproduces the problem, then please zip the save and post it in a reply if it can be attached (might not due to size limits).

If you can't do that, then please attach all the .log files from immediately after getting the error. Ideally load a game that produces the issue after a single turn, and delete all the logs before producing the error, to be sure you're getting only fresh log files.

The logs (and saves) are in the directory discussed here: http://freeorion.org/index.php/Config.xml

knelson
Space Krill
Posts: 6
Joined: Tue Oct 20, 2015 10:51 pm

Re: Error Writing To Save File

#3 Post by knelson »

The saved file and the log files when zipped where still too large to attach. You can download the zipped log file and game file from the links below.

http://newage-mkt.com/AI_8.zip
http://newage-mkt.com/FreeOrion_Save.zip

Thanks,

Keith

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Error Writing To Save File

#4 Post by Vezzra »

@knelson: What platform are you running on? What are your system specs?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Error Writing To Save File

#5 Post by Geoff the Medio »

I loaded the save with the latest master build, pressed turn, and it seemed to work fine. Ran a few more turns with turn autocycle on, and eventually got the error popup. In the server log, I see

Code: Select all

2016-01-22 11:58:09.244977 [error] Server : SaveLoad.cpp:171 : Error when writing save file. SaveGame exception: : output stream error
which is not especially helpful. I'm adding some extra logging now...

Edit: the preceeding line appears to be actually indicating where it's failing, which is when serializing the stat records... which is a bit surprising as that's just a nested bunch of std containers / data.

Edit2: The problem seems to occur when serializing to XML, and before the compression is attempted. I'm guessing / it seems like some limit or buffer being exhausted when writing too much data, which just happens to occur for this game when attempting to serialize the stat records.

I suggest: Before loading a game, go into the options screen, scroll to the far-right "Other" tab, and enable Binary Serialization. Then load the game and attempt to continue playing. This seems to more-reliably produce autosaves for me, without any errors popping up. The resulting saves won't be cross-platform compatible, but should work fine on your own system.

knelson
Space Krill
Posts: 6
Joined: Tue Oct 20, 2015 10:51 pm

Re: Error Writing To Save File

#6 Post by knelson »

I am using a windows platform.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Error Writing To Save File

#7 Post by Geoff the Medio »

Geoff the Medio wrote:Edit2: The problem seems to occur when serializing to XML, and before the compression is attempted. I'm guessing / it seems like some limit or buffer being exhausted when writing too much data, which just happens to occur for this game when attempting to serialize the stat records.
I've moved the stringstream used for storing the XML serialization data onto the heap, instead of the stack, in the hope that this would also move the buffer, and added custom NVP-serialization name tags for meter current and initial values, in the hope of reducing the size of the serialized text. Doesn't seem to have helped, though.

I also somewhat randomly have errors reading in the save, due to "bad allocation" errors, when attempting to decompress the saved serialization text. Sometimes it happens, sometimes not, for no apparent reason. Rebuilding after making some code change seems to help sometimes.

I also put some debug log output to check the size of the stringstream into which save data is serialized, and it gets up to ~70 MB before the universe stuff is serialized, which is a bit surprisingly large, and supports the buffer limit theory. Haven't been able to find any way to pre-allocate a buffer for the stringstream, though.

UrshMost
Space Kraken
Posts: 123
Joined: Fri Jul 03, 2015 2:32 am
Location: Great White North Eh

Re: Error Writing To Save File

#8 Post by UrshMost »

FYI, I have been occasionally getting these errors as well, always late game, but have never been able to reproduce them. I have auto save set to generate every turn, and reloading the previous turn's autosave has always worked, although sometimes freeorion needs to be restarted first.
Windows 10 64bit, AMD 8 Core, 16 GB
Nvidia GTX 670 @ 3240x1920
FreeOrion Build: Latest Windows Test Build

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Error Writing To Save File

#9 Post by Geoff the Medio »

I tried replacing stringstream by an std::string wrapped using some boost iostreams wrappers: back_insert_device<std::string>, and stream<back_insert_device<std::string> >. This lets me manually reserve space to increase the buffer capacity, so as to avoid repeatedly reallocating more memory in order to store serialized text data as it is generated while saving.

This works fine for loading saves, but it inexplicably breaks when serializing to text in order to write a new save. If I look at the contents of the buffer after serializing, it suddenly stops mid-entry. This occurs even when serializing a small new game gamestate, so is seemingly not an issue with the buffer size, unless there's some other internal buffer I'm not aware of.

Edit: Eventually found that I needed to add calls to flush the stream to the buffer. After that, it seems to work. Try loading the save and playing again with the next test build.

UrshMost
Space Kraken
Posts: 123
Joined: Fri Jul 03, 2015 2:32 am
Location: Great White North Eh

Re: Error Writing To Save File

#10 Post by UrshMost »

I just played a large game to a little over 400 turns without any save errors, and have had multiple games in the 250 - 300 turn range, also without any save errors, on the Feb 09 Build. I think you fixed it.
Windows 10 64bit, AMD 8 Core, 16 GB
Nvidia GTX 670 @ 3240x1920
FreeOrion Build: Latest Windows Test Build

dariomor
Space Krill
Posts: 3
Joined: Thu Jun 09, 2016 2:57 am

Re: Error Writing To Save File

#11 Post by dariomor »

UrshMost wrote:I just played a large game to a little over 400 turns without any save errors, and have had multiple games in the 250 - 300 turn range, also without any save errors, on the Feb 09 Build. I think you fixed it.
Sorry, but I dont think so...

O got the "Error when writing save file" today.

v0.4.5+ build 2016-06-06.4187172

Windows 7 ultlimate 64 SP1

8 GB RAM, i3-2100, game on C: SSD drive, savegame folder in D: conventional HD.

I also cannot save game thru the main menu. All save tries since turn 380 results on a empty file (size = 0)

Frustrating... a so big game wich I could win...

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: Error Writing To Save File

#12 Post by dbenage-cx »

If you were able to save before with the same build, is the drive full or read-only?

A couple of issues were fixed around the same time as your build, you might try a more recent build. Failing that, could you attach the freeorion.log and freeoriond.log files?
Any content posted should be considered licensed GNU GPL 2.0 and/or CC-BY-SA 3.0 as appropriate.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Error Writing To Save File

#13 Post by Geoff the Medio »

dbenage-cx wrote:...could you attach the freeorion.log and freeoriond.log files?
When reporting such issues, the logs should be attached unless there's a reason not to.
dariomor wrote:All save tries since turn 380 results on a empty file (size = 0)
If you can find a previous save from the same game, which can be used to reproduce the issue, then attaching that (or more likely posting it somewhere else and linking, as it would presumably be too large a file for the forums), would be helpful.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Error Writing To Save File

#14 Post by MatGB »

I don't know if this is related but I sometimes get blank 0Kb saves, and it's happened to me both on Windows and Linux, it's never happened to an autosave and only ever to a save I make just before shutting the game down.

I never notice it's happened until I reboot the game and try to load my last save, so log files aren't useful, I have now got the directory open so I can check the filesize and similar, screenshot attached.
savegame-failures.png
savegame-failures.png (112.8 KiB) Viewed 1652 times
Due to absence of valid logs, not sure where to start looking, but as it happens on both my machines (I don't use the Windows laptop much for FO but it has happened there) it appears to be more than just a personal settings glitch.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Error Writing To Save File

#15 Post by Geoff the Medio »

If it's happening with 3 MB save files, it's not related to the previous issue with overly large universes.

A log or way to reproduce will be needed, though...

Post Reply