PongUIO/AndroidWars — Issue #9: Improve simulation serialization safety
Author: Thekian
Created: 2012-02-24 19:08:16+00:00
State: open
Labels: simulation

Currently, the entire simulation is serialized straight into a single Sim::Save object when saved. This has caused severe bugs in the past when the serialized stream has been loaded, but not aligned properly (due to accidental differences between the functions that save and load).

Two improvements is suggested to this system.

The first improvement is to have related sub-chunks saved independently, then assembled into one large Save object. This is easy to do since a Save object can store nested Save objects (using Save::writeSave()/readSave() ). This has the downside of requiring an extra 4-byte per nested Save, but this overhead is minimal if not overused. It is suggested to have independent Save objects for each sub-component in Sim::State.

The second improvement is to check for alignment using assertions or similar for these nested Save objects. When a Save is loaded in this manner, it should be checked that, after loading, the read pointer is equivalent to the size of the Save. While this may not catch all issues, it should catch the majority.

One possible implementation is to use a pair of functions in Sim::Save that adds this kind of support through a simple wrapper, and use these to implement a wrapper in State::save/load to utilize these per component.

See: simulation/Save.h/.cpp, simulation/State.h/.cpp