CleverRaven/Cataclysm-DDA — pull request #9700 by BevapDin (2014-10-27 00:40:24+00:00)
Title: Loading items from old saves checks for items counted by charges that have no charges and repairs them.

Fixes the crash from http://smf.cataclysmdda.com/index.php?topic=8120

Should also fix #7211 as it restores the default charges when loading an item with invalid charges count.

----

The bug is caused by 64abc9b1b7dade662b8747190908362654e9828e, it changed the soap item from being a generic item to being a comestible with charges. Generic items always have `charges == -1`, therefor soap items generated before that commit had `charges == -1`.

When a new version of the game loads an old save, it loads the charges charges without checking them. But there should be no item (that is counted by charges) with `charges <= 0` (that makes no sense, imagine `cookies (0)`), this is tested in the advanced inventory and the test fails with an assertion error, leading to the crash in the bug report.

This restores the charges member to the proper default value, taken from a freshly created item of the same type.