Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #77500 - Repeatable crash when interacting with an item #77551

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

RenechCDDA
Copy link
Member

Summary

Bugfixes "Fix a crash when examining or eating certain food items"

Purpose of change

Describe the solution

Check if our comestible data is nullptr before trying to access it

Also noticed I set must_be_food incorrectly, by checking if the vitamins were empty. Reversed that, must_be_food is set to true if the vitamins are not empty.

Describe alternatives you've considered

Testing

Should work but I haven't personally tested it

Additional context

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Nov 3, 2024
@Maleclypse
Copy link
Member

What's the best way for me to test this after compiling it?

@RenechCDDA
Copy link
Member Author

I would reproduce the crash in the linked issue without the patch consistently, then apply the patch and see if it still happens.

@RadioAndrea
Copy link

RadioAndrea commented Nov 4, 2024

I have compiled and tested this with my own save that is enjoying the same issue.

#77551 does not resolve #77500 for me.

The same behavior of attempting to "pick up, examine, autohaul, use the item look around menu with, or use AIM on the pile of items" results in segfault.

Crash log for reference:

The program has crashed.
See the log file for a stack trace.
CRASH LOG FILE: ./config/crash.log
VERSION: cdda-experimental-2024-11-03-1140 9f98a020f3
TYPE: Signal
MESSAGE: SIGSEGV: Segmentation fault
STACK TRACE:

    ./cataclysm-tiles(debug_write_backtrace(std::ostream&)+0x25) [0x141cae5]
    ./cataclysm-tiles() [0x13dfa0d]
    ./cataclysm-tiles() [0x13df68e]
    /lib64/libc.so.6(+0x40d00) [0x7f8d36f6bd00]
    ./cataclysm-tiles(nutrients::kcal() const+0xa) [0x25336da]
    ./cataclysm-tiles(item::made_of_any_food_components(bool) const+0xff) [0x18b661f]
    ./cataclysm-tiles(Character::compute_effective_nutrients(item const&) const+0x61) [0x1370e81]
    ./cataclysm-tiles(item::has_vitamin(string_id<vitamin> const&) const+0x4c) [0x187a5dc]
    ./cataclysm-tiles(Character::will_eat(item const&, bool) const+0x378) [0x1376728]
    ./cataclysm-tiles(item::color_in_inventory(Character const*) const+0x694) [0x18a9274]
    ./cataclysm-tiles() [0x1a0054b]
    ./cataclysm-tiles(tname::print_segment[abi:cxx11](tname::segments, item const&, unsigned int, enum_bitset<tname::segments> const&)+0x1c) [0x19fba5c]
    ./cataclysm-tiles(item::tname[abi:cxx11](unsigned int, enum_bitset<tname::segments> const&) const+0x78) [0x185f808]
    ./cataclysm-tiles(inventory_entry::update_cache()+0x131) [0x181f951]
    ./cataclysm-tiles(inventory_column::add_entry(inventory_entry const&)+0x34c) [0x182423c]
    ./cataclysm-tiles(inventory_selector::add_entry(inventory_column&, std::vector<item_location, std::allocator<item_location> >&&, item_category const*, unsigned long, item_location const&, bool)+0x1bb) [0x182a5eb]
    ./cataclysm-tiles(inventory_selector::add_entry_rec(inventory_column&, inventory_column&, item_location&, item_category const*, item_category const*, item_location const&, int)+0x1b4) [0x182a8d4]
    ./cataclysm-tiles(inventory_selector::_add_map_items(tripoint const&, item_category const&, item_stack&, std::function<item_location (item&)> const&)+0x118) [0x182d0b8]
    ./cataclysm-tiles(inventory_selector::add_map_items(tripoint const&)+0x275) [0x182cd15]
    ./cataclysm-tiles(game_menus::inv::pickup[abi:cxx11](std::optional<tripoint> const&, std::vector<std::pair<item_location, int>, std::allocator<std::pair<item_location, int> > > const&)+0x151) [0x1700fb1]

    Attempting to repeat stack trace using debug symbols…
    debug_write_backtrace(std::ostream&)
    …/src/debug.cpp:1253
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider::_Alloc_hider(char*, std::allocator<char> const&)
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/basic_string.h:194
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::allocator<char> const&)
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/basic_string.h:541
    std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/sstream:251
    std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::str() const
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/sstream:931
    log_crash(char const*, char const*)
    …/src/crash.cpp:90
    signal_handler(int)
    …/src/crash.cpp:152
    ??
    ??:0
    nutrients::kcal() const
    …/src/stomach.cpp:125
    item::made_of_any_food_components(bool) const
    …/src/item.cpp:?
    Character::compute_effective_nutrients(item const&) const
    …/src/consumption.cpp:326
    item::has_vitamin(string_id<vitamin> const&) const
    …/src/item.cpp:?
    Character::will_eat(item const&, bool) const
    …/src/consumption.cpp:983
    ret_val<edible_rating>::value() const
    …/src/ret_val.h:92
    item::color_in_inventory(Character const*) const
    …/src/item.cpp:6402
    (anonymous namespace)::contents[abi:cxx11](item const&, unsigned int, enum_bitset<tname::segments> const&)
    …/src/item_tname.cpp:239
    tname::print_segment[abi:cxx11](tname::segments, item const&, unsigned int, enum_bitset<tname::segments> const&)
    …/src/item_tname.cpp:620
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/basic_string.h:1077
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/basic_string.h:1436
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/basic_string.h:1378
    item::tname[abi:cxx11](unsigned int, enum_bitset<tname::segments> const&) const
    …/src/item.cpp:6865
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data() const
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/basic_string.h:228
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::data() const
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/basic_string.h:2654
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator std::basic_string_view<char, std::char_traits<char> >() const
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/basic_string.h:950
    (anonymous namespace)::get_cached_name(item const*)
    …/src/inventory_ui.cpp:100
    inventory_entry::update_cache()
    …/src/inventory_ui.cpp:601
    inventory_column::add_entry(inventory_entry const&)
    …/src/inventory_ui.cpp:1330
    inventory_selector::add_entry(inventory_column&, std::vector<item_location, std::allocator<item_location> >&&, item_category const*, unsigned long, item_location const&, bool)
    …/src/inventory_ui.cpp:?
    inventory_selector::add_entry_rec(inventory_column&, inventory_column&, item_location&, item_category const*, item_category const*, item_location const&, int)
    …/src/inventory_ui.cpp:1954
    inventory_selector::_add_map_items(tripoint const&, item_category const&, item_stack&, std::function<item_location (item&)> const&)
    …/src/inventory_ui.cpp:2154
    inventory_selector::add_map_items(tripoint const&)
    /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/std_function.h:243
    game_menus::inv::pickup[abi:cxx11](std::optional<tripoint> const&, std::vector<std::pair<item_location, int>, std::allocator<std::pair<item_location, int> > > const&)
    …/src/game_inventory.cpp:2214

Can provide additional save file if desired.

Cheers

@RenechCDDA
Copy link
Member Author

@RadioAndrea I don't know your workflow but your log indicates that you are using the release binary and not a compiled version.

I've tested this now with the save from the linked issue and it resolves the crash.

@Maleclypse Maleclypse merged commit e425f39 into CleverRaven:master Nov 5, 2024
19 of 26 checks passed
@RadioAndrea
Copy link

@RadioAndrea I don't know your workflow but your log indicates that you are using the release binary and not a compiled version.

I've tested this now with the save from the linked issue and it resolves the crash.

RIP

Sorry about that.

It's my first time building cata from source, I must have done something wrong!

Cheers!

@RadioAndrea
Copy link

I checked it again, yes I messed up and used old executable.

Showing as fixed in this new revision.

My 12 3L jars of Cherries (Fresh) (Sealed) no longer destroy the game.

Thank you for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repeatable crash when interacting with an item
4 participants