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 when equipping thermal electric outfit while naked #75111

Closed morikal closed 1 month ago

morikal commented 2 months ago

Describe the bug

When naked, go to the + menu (armor/layer sorting) and navigate to the torso. Press 'E' to equip armor to this location, equip thermal electric outfit -> segfault.

Note that if I don't drop all my worn things first, there is no crash. Further, even if I do drop all my things first, if I equip via the 'W'ear action there is no crash.

crash.log

Attach save file

South Holland-trimmed.tar.gz

Steps to reproduce

  1. Drop all worn items.
  2. Walk a few tiles north to where the pile with the thermal electric outfit is.
  3. Press + to open armor layering UI
  4. Navigate to torso section
  5. Hit E to equip armor to this location
  6. Select the thermal electric outfit

Expected behavior

No crash

Screenshots

No response

Versions and configuration

Additional context

No response

NoddingCrow commented 2 months ago

Confirmed on cdda-experimental-2024-07-19-1400 b1cf8e3 [64-bit] from earlier in the day too; segfault occurs when equipping any worn item onto a naked character through the armor sort screen.

No-location / cosmetic items crash the game too.

Integrated armor saves it from crashing, but pop-up "Can't put this on under your integrated armor!" seems to suggest it's attempting to place them "below" the integrated armor item and is being successfully caught.

PatrikLundell commented 1 month ago

Tried to fix this by checking if tmp_worn was empty and emplace the new item at both the back and the front of "worn" if it was, rather than to try to get the first element of an empty vector (and crash) . In both cases it doesn't crash, but I end up with two copies of the item worn, and it appears I get duplication when those are take off.

Edit: Realized duplication was because the splicing was moving, not inserting, and that insertion had already been done above. Thus, the whole "rearrange to align cursor" stuff could simply be skipped if the list was empty.