CleverRaven / Cataclysm-DDA

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

Errors examining or picking up items dropped by dead NPC #37339

Closed wapcaplet closed 4 years ago

wapcaplet commented 4 years ago

Describe the bug

After I killed NPC Omar Bender inside my base in self-defense, he dropped a bunch of items, including a radio and crossbow that emit errors when I try to examine or grab them:

 DEBUG    : Requested non-existing faction 'solo_Omar Bender'
 FUNCTION : faction* faction_manager::get(const faction_id&, bool)
 FILE     : src/faction.cpp
 LINE     : 456

followed by:

 DEBUG    : item::get_owner_name() item two-way radio has no valid nor null faction id 
 FUNCTION : std::__cxx11::string item::get_owner_name() const
 FILE     : src/item.cpp
 LINE     : 1087

Steps To Reproduce

Steps to reproduce the behavior:

  1. Kill a hostile NPC
  2. See if they drop any items
  3. Try to examine or pick up their loot

Expected behavior

Expected all of dead NPC's items to have similar ownership/faction attributes. Or, if there is some reason his radio and crossbow are owned by another faction, at least there should be no errors trying to examine them.

Screenshots

Here are the two problematic items once I moved the corpse and clothing aside. Attempting to move them using advanced inventory manager or hauling simply does nothing (which seems fine, if these items aren't mine), but I only see errors if I try to examine or grab them:

image

Versions and configuration

wapcaplet commented 4 years ago

I was able to reproduce this a couple more times in a build from master today (0.D-11818-g2c8919d95b) with these steps:

Once, the faulty item was a pot helmet; another time, a Mossberg 500 Security shotgun.

I have not tried killing friendly NPCs to see if it affects them too, but I might have to take the morale penalty and do it for science.

Attaching save game with a nearby corpse; the Mossberg 500 can't be examined or picked up, and shows up in red text:

image

Save game: NPCville_CDDA_savegame.zip

Now that I'm sure I can reproduce the issue, I will try cracking this and submit a PR if I can figure out a fix.

wapcaplet commented 4 years ago

I located the code that deals with factions after an NPC's death but it'll take some time for me to grok it:

https://github.com/CleverRaven/Cataclysm-DDA/blob/2c8919d95bfe93c3c719464017425ea0eee315d1/src/npc.cpp#L2406-L2417

It looks like this bit is part of the "lone wolf" faction system added / revised back in September 2019:

https://github.com/CleverRaven/Cataclysm-DDA/commit/9155080da9b94b1d5400ff59ce47d55ed67dc4c2#diff-529d096f96854d0d52b251607dce9f6e

My guess is the faction was deleted after the NPC's death, but one of the dropped items remained attached to that faction ID somehow.

ghost commented 4 years ago

Cant reproduce, but can reproduce linked issue which is a different circumstance.

ghost commented 4 years ago

Well, either way, the linked PR will fix all future instances of this type of bug, hopefully