Cataclysm-dda: game crash on save corrupts save file

Created on 29 Jun 2019  路  8Comments  路  Source: CleverRaven/Cataclysm-DDA

Describe the bug

At some point I've tried to exit the game, and it crashed mid-process.
When trying to load - it gives error about BAD json

 DEBUG    : Bad save json
EOF: expecting string but found '

 FUNCTION : void game::unserialize(std::istream&)
 FILE     : src/savegame.cpp
 LINE     : 244

I've lost 2 IRL game evenings since last backup, so restored the save from backup and continued from there. After a while this happened again.
Somehow this relates to CBM installation - if I don't install cbms - game plays fine.
But if I do CBM installation attempt and exit the game - it will crash.
A workaround (not reliable) - was to wait some time for autosave to kick in automatically, and then the save file isn't corrupted.

Steps To Reproduce

  1. Load attached save file - select Garret Bonner.
  2. Enter the military bunker to the south.
  3. Attempt to install one of available CBMs.
  4. Try to exit and save the game. Observe SEGFAULT error message, and crash to desktop.
  5. Try reloading - save is corrupted.

Expected behavior

Crashes to desktop are bad, mkay? Crashes, which corrupt one's save files, are even worse...

Versions and configuration

Save file
Homo-homini-cbm-installs-fourth.zip
GAME REPORT:

  • OS: Linux

    • OS Version: Distributor ID: LinuxMint; Description: Linux Mint 18.3 Sylvia; Release: 18.3; Codename: sylvia;

  • Game Version: 0.D-5097-g8bf1d64 [64-bit]
  • Graphics Version: Tiles
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Makeshift Items Mod [makeshift],
    Medieval and Historic Classes and Shields [Medieval_Stuff],
    Mutant NPCs [mutant_npcs],
    Folding Parts pack [deoxymod]
    ]

crash.log excerpt:

10:45:13.025 : Starting log.
10:45:13.025 INFO : Cataclysm DDA version 0.D-5097-g8bf1d64
10:45:13.032 ERROR : (error message will follow backtrace)
    ./cataclysm-tiles(_Z21debug_write_backtraceRSo+0x38) [0x8e9a1e]
    ./cataclysm-tiles(_Z8DebugLog10DebugLevel10DebugClass+0x1e1) [0x8ea66f]
    ./cataclysm-tiles() [0xd0a42a]
    ./cataclysm-tiles(_Z14read_from_fileRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt8functionIFvRSiEE+0x85) [0x87193c]
    ./cataclysm-tiles() [0xd09abc]
    ./cataclysm-tiles(_ZN15options_manager19build_tilesets_listEv+0x6e) [0xd0a098]
    ./cataclysm-tiles(_ZN15options_manager20add_options_graphicsEv+0x117e) [0xd0dd12]
    ./cataclysm-tiles(_ZN15options_manager4initEv+0x169) [0xd1c7c1]
    ./cataclysm-tiles(main+0xe87) [0x7656f2]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f7a7c6a5830]
    ./cataclysm-tiles(_start+0x29) [0x7acb59]

    Attempting to repeat stack trace using debug symbols...
    debug_write_backtrace(std::ostream&)
    ??:?
    DebugLog(DebugLevel, DebugClass)
    ??:?
    build_resource_list(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(std::istream&)#1}::operator()(std::istream&) const [clone .constprop.497]
    options.cpp:?
    read_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void (std::istream&)> const&)
    ??:?
    build_resource_list(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [clone .constprop.496]
    options.cpp:?
    options_manager::build_tilesets_list()
    ??:?
    options_manager::add_options_graphics()
    ??:?
    options_manager::init()
    ??:?
    main
    ??:?
    __libc_start_main
    /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:325
    _start
    ??:?
Backtrace emission took 0 seconds.
Found tileset duplicate with name MSX++DEAD_PEOPLE
10:45:13.307 ERROR : Found tileset duplicate with name MSX++DEAD_PEOPLE
10:45:13.307 ERROR : Found tileset duplicate with name UNDEAD_PEOPLE
10:45:13.307 INFO : Number of render drivers on your system: 3
10:45:13.307 INFO : Render driver: 0/opengl
10:45:13.307 INFO : Render driver: 1/opengles2
10:45:13.307 INFO : Render driver: 2/software
10:45:13.586 INFO : SDL version used during compile is 2.0.4
10:45:13.586 INFO : SDL version used during linking and in runtime is 2.0.4
10:45:13.749 INFO : Active renderer: 1/opengles2
10:45:13.839 INFO : USE_COLOR_MODULATED_TEXTURES is set to 0
10:45:13.934 WARNING : opendir [./mods/] failed with "No such file or directory".
10:45:17.726 WARNING : opendir [./save/Homo-homini/mods] failed with "No such file or directory".
10:45:24.654 INFO : Loaded tileset: MSX++DEAD_PEOPLE
10:45:25.015 ERROR : src/savegame.cpp:244 [void game::unserialize(std::istream&)] Bad save json
EOF: expecting string but found '

-----------------------------------------
<Crash / Freeze>

Most helpful comment

31992 fixes this particular crash, but leaving this issue open as a reminder that crashes during saves ought not to corrupt the save.

All 8 comments

Just realized I didn't attach the actual crash.log file...
crash.log
@jbytheway can it be related to your recent changes in item.h and others?

Yes, thanks for drawing my attention. It looks like unpack in one of the item_location derived classes returned nullptr, which ensure_unpacked doesn't handle. If so, the crash is relatively easy to fix, although it's a symptom of the underlying unsafety of item_location serialization which we're not sure how to fix. I'll try to get a PR done tomorrow to at least fix the crash.

Can't you just write your updated files to a temporary directory and move them over the existing ones when you're done?

That might be a good idea, but that's a separate issue from what I was discussing.

31992 fixes this particular crash, but leaving this issue open as a reminder that crashes during saves ought not to corrupt the save.

@jbytheway Thanks for solving this!

Apparently, I'm still having the issue.
After clearing another lab, I get the error message about items missing on save/load cycle, and when time comes for an autosave it crashes, and corrupts the save file.
I noticed I've lost some items somewhere between those saves - namely a Glock with several attached mods which I used to train handgun skills, and earlier than that a jackhammer which I found on week 1 and carried in the vehicle ever since.

Excerpt from debug.log:

20:59:36.934 : Starting log.
20:59:36.935 INFO : Cataclysm DDA version 0.D-5189-g53ea66f
20:59:36.959 ERROR : (error message will follow backtrace)
    ./cataclysm-tiles(_Z21debug_write_backtraceRSo+0x38) [0x8ec1ea]
    ./cataclysm-tiles(_Z8DebugLog10DebugLevel10DebugClass+0x1e1) [0x8ece3b]
    ./cataclysm-tiles() [0xd0d64a]
    ./cataclysm-tiles(_Z14read_from_fileRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt8functionIFvRSiEE+0x85) [0x871af2]
    ./cataclysm-tiles() [0xd0ccdc]
    ./cataclysm-tiles(_ZN15options_manager19build_tilesets_listEv+0x6e) [0xd0d2b8]
    ./cataclysm-tiles(_ZN15options_manager20add_options_graphicsEv+0x117e) [0xd10f32]
    ./cataclysm-tiles(_ZN15options_manager4initEv+0x169) [0xd1f9e1]
    ./cataclysm-tiles(main+0xe87) [0x766454]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7fe330c09830]
    ./cataclysm-tiles(_start+0x29) [0x7ac2c9]

    Attempting to repeat stack trace using debug symbols...
    debug_write_backtrace(std::ostream&)
    ??:?
    DebugLog(DebugLevel, DebugClass)
    ??:?
    build_resource_list(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(std::istream&)#1}::operator()(std::istream&) const [clone .constprop.493]
    options.cpp:?
    read_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void (std::istream&)> const&)
    ??:?
    build_resource_list(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [clone .constprop.492]
    options.cpp:?
    options_manager::build_tilesets_list()
    ??:?
    options_manager::add_options_graphics()
    ??:?
    options_manager::init()
    ??:?
    main
    ??:?
    __libc_start_main
    /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:325
    _start
    ??:?
Backtrace emission took 1 seconds.
Found tileset duplicate with name MSX++DEAD_PEOPLE
20:59:37.427 ERROR : Found tileset duplicate with name MSX++DEAD_PEOPLE
20:59:37.427 ERROR : Found tileset duplicate with name UNDEAD_PEOPLE
20:59:37.427 INFO : Number of render drivers on your system: 3
20:59:37.427 INFO : Render driver: 0/opengl
20:59:37.427 INFO : Render driver: 1/opengles2
20:59:37.427 INFO : Render driver: 2/software
20:59:37.914 INFO : SDL version used during compile is 2.0.4
20:59:37.915 INFO : SDL version used during linking and in runtime is 2.0.4
20:59:38.152 INFO : Active renderer: 1/opengles2
20:59:38.315 INFO : USE_COLOR_MODULATED_TEXTURES is set to 0
20:59:38.486 WARNING : opendir [./mods/] failed with "No such file or directory".
20:59:45.704 WARNING : opendir [./save/Homo-homini/mods] failed with "No such file or directory".
20:59:55.783 INFO : Loaded tileset: MSX++DEAD_PEOPLE
21:05:00.246 ERROR : (error message will follow backtrace)
    ./cataclysm-tiles(_Z21debug_write_backtraceRSo+0x38) [0x8ec1ea]
    ./cataclysm-tiles(_Z8DebugLog10DebugLevel10DebugClass+0x1e1) [0x8ece3b]
    ./cataclysm-tiles(_Z12realDebugmsgPKcS0_S0_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0xb0) [0x8ed8f1]
    ./cataclysm-tiles(_Z12realDebugmsgIJEEvPKcS1_S1_S1_DpOT_+0x43) [0x7d0924]
    ./cataclysm-tiles() [0xa895ee]
    ./cataclysm-tiles(_ZNK13item_location4impl6targetEv+0xf) [0xa8a58f]
    ./cataclysm-tiles(_ZNK13item_location4impl14item_on_person9serializeER7JsonOut+0x59) [0xa8a7d3]
    ./cataclysm-tiles(_ZNK6player5storeER7JsonOut+0xb2c) [0xe41768]
    ./cataclysm-tiles(_ZNK6avatar5storeER7JsonOut+0x27) [0xe41aa1]
    ./cataclysm-tiles(_ZNK6avatar9serializeER7JsonOut+0x1e) [0xe422a0]
    ./cataclysm-tiles(_ZN4game9serializeERSo+0x50b) [0xe2b1e1]
    ./cataclysm-tiles(_Z13write_to_fileRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt8functionIFvRSoEEPKc+0x43) [0x871e3d]
    ./cataclysm-tiles(_ZN4game16save_player_dataEv+0x7b) [0x979ff7]
    ./cataclysm-tiles(_ZN4game4saveEv+0x21) [0x98507d]
    ./cataclysm-tiles(_ZN4game9quicksaveEv+0x5a) [0x985302]
    ./cataclysm-tiles(_ZN4game8autosaveEv+0x64) [0x985394]
    ./cataclysm-tiles(_ZN4game7do_turnEv+0x1eb) [0x9a22eb]
    ./cataclysm-tiles(main+0x166d) [0x766c3a]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7fe330c09830]
    ./cataclysm-tiles(_start+0x29) [0x7ac2c9]

    Attempting to repeat stack trace using debug symbols...
    debug_write_backtrace(std::ostream&)
    ??:?
    DebugLog(DebugLevel, DebugClass)
    ??:?
    realDebugmsg(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
    ??:?
    void realDebugmsg<>(char const*, char const*, char const*, char const*)
    ??:?
    item_location::impl::ensure_unpacked() const [clone .part.249] [clone .constprop.365]
    item_location.cpp:?
    item_location::impl::target() const
    ??:?
    item_location::impl::item_on_person::serialize(JsonOut&) const
    ??:?
    player::store(JsonOut&) const
    ??:?
    avatar::store(JsonOut&) const
    ??:?
    avatar::serialize(JsonOut&) const
    ??:?
    game::serialize(std::ostream&)
    ??:?
    write_to_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void (std::ostream&)> const&, char const*)
    ??:?
    game::save_player_data()
    ??:?
    game::save()
    ??:?
    game::quicksave()
    ??:?
    game::autosave()
    ??:?
    game::do_turn()
    ??:?
    main
    ??:?
    __libc_start_main
    /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:325
    _start
    ??:?
Backtrace emission took 0 seconds.
src/item_location.cpp:97 [void item_location::impl::ensure_unpacked() const] item_location lost its target item during a save/load cycle

I see the debugmsg about a lost item, and indeed it's possible that's related to a later crash if you observed one, but do you have a backtrace from the crash itself?

Was this page helpful?
0 / 5 - 0 ratings