CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.26k stars 4.12k forks source link

Segfault on unloading bottle of antacid tablets #75156

Closed AzyWng closed 1 month ago

AzyWng commented 1 month ago

Describe the bug

Got a segmentation fault when attempting to unload a bottle of antacid pills (specifically, one that only had one pill inside) while possessing other bottles of antacid pills.

Attach save file

Summers-trimmed.tar.gz

Steps to reproduce

  1. Get several bottles of antacid pills that are not full - and one bottle with only one pill.
  2. Unload the bottle of antacid pills that only has one pill.
  3. Crash.

Expected behavior

I expected the single antacid pill to transfer to one of the bottles with more antacid pills, without crashing.

Screenshots

No response

Versions and configuration

Additional context

pills crash.zip

PatrikLundell commented 1 month ago

/Confirmed

Happened with both the single pill and 4 pill bottles (the two I've tried so far).

Edit: It blows up when iterating over 3 kinds of pockets. It successfully removes the item(s) from the CONTAINER, but then blows up moving on to MAGAZINE_WELL. The time has a pocket of type CONTAINER that contained the pill(s), plus a pocket of type MIGRATION, which isn't one of the types iterated over.

It seems unload_activity_actor::unload parameter target gets invalidated after the CONTAINER pocket is processed.

Edit 2: Modifying activity_actor.cpp operation activity_actor::unload (the same mentioned above) by moving the "if (changed)" section out of the pocket "for" loop (i.e. placing it immediately before "return"). Seems to sort of work. It didn't crash, but the single pill seemed to be unloaded into the four pill bottle, and that bottle, the now empty bottle, and one containing some other medication were dropped onto the ground, even though the message was that the pill was moved into the inventory. When unloading the 9 pill bottle 8 of the pills ended up with the 17 cold pills in their bottle and the last one ended up in the inventory.

I'm giving up here, as there seem to be a lot going on that don't feel qualified to tackle.

inogenous commented 1 month ago

The savegame has the antacid-pill-bottles inside a steel pan, which itself is in the backpack. When unloading the single pill bottle, this will cause the steelpan to spill its contents. This spilling, in turn, invalidates the item_location and the item. Normally, the items would spill to inventory, but since all eligible pockets are full, the pill bottles will spill from the steelpan onto the ground.

Having the pillbottles inside the steelpan like that should not be possible since the steelpan is a spillable container, but apparently it is, and that's possibly a separate issue.

75299 resolves the segfault, and adds a user-shown message when spilling items from the steelpan (The plastic bottle falls out of the steel frying pan).