Added sanity check in player inventory layouting code for GUIs, fixes #541.
Made edit create a temporary backup of the file being edited when saving, to avoid losing data when erroring while saving (e.g. out of memory). Closes #534.