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

NPCs attempting to wield a weapon that's in a holster but loose in their inventory crashes game #2947

Closed
chaosvolt opened this issue Jun 8, 2023 · 0 comments · Fixed by #2948
Labels

Comments

@chaosvolt
Copy link
Member

Describe the bug

If you holster or sheath a weapon, and then give it to an NPC so they put that item loose in their inventory instead of wielding it, the game will close outright with a read access violation when they decide they want to wield that weapon. Results from testing in VS:

Exception thrown: read access violation.
**who** was nullptr.
>	cataclysm-tiles.exe!character_funcs::try_wield_contents(Character & who, item & container, item * internal_item, bool penalties, int base_cost) Line 533	C++
 	cataclysm-tiles.exe!holster_actor::use(player & p, item & it, bool __formal, const tripoint & __formal) Line 2781	C++
 	cataclysm-tiles.exe!itype::invoke(player & p, item & it, const tripoint & pos, const std::string & iuse_name) Line 211	C++
 	cataclysm-tiles.exe!Character::invoke_item(item * used, const std::string & method, const tripoint & pt) Line 7235	C++
 	cataclysm-tiles.exe!npc::wield(item & it) Line 1186	C++
 	cataclysm-tiles.exe!npc::wield_better_weapon() Line 3570	C++
 	cataclysm-tiles.exe!npc::method_of_attack() Line 1372	C++
 	cataclysm-tiles.exe!npc::move() Line 785	C++
 	cataclysm-tiles.exe!game::monmove() Line 4166	C++
 	cataclysm-tiles.exe!game::do_turn() Line 1510	C++
 	cataclysm-tiles.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 739	C++
 	[External Code]	

From discussion in the BN discord, @KheirFerrum has so far found the apparent cause but a fix evidently might be a bit of work:

[12:28 PM]Kheir: OK, figured it out.
[12:28 PM]Kheir: They can't invoke holsters properly.
[12:28 PM]Kheir: If worn they use remove_item() which seems to work perfectly fine.
[12:29 PM]Chaosvolt: Nice.
[12:29 PM]Kheir: Though this raises a concern since this probably means they don't put weapons away into holsters/sheaths?

Steps To Reproduce

  1. Recruit an NPC, for best results leave them unarmed and naked except for a backpack so they'll have no choice as to what weapon to pick.
  2. Hand them a weapon stashed in a holster/sheath. Examples tested so far include a zweihander tucked into a back scabbard, a combat knife tucked into a sheath, and an M9 tucked into a
  3. Spawn in a menacing debug monster, within a few turns the game will close outright, either after a few turns of sitting there if the item was a holstered gun, or after waling up to the target if it was a sheathed melee weapon.
  4. Give them an item to wield beforehand, they'll behave as normal. For now. For example, giving them both a loaded pistol to wield and another locked behind the Holster of Doom works fine until they run out of ammo, then the game will implode once they notice they have another gun somewhere they evidently can't reach without the game imploding.
  5. Additionally try giving them a sheathed sword or the like to wear instead of loose in inventory. They'll draw the weapon in a worn sheath/holster with no issues, though you'll need to take care that they actually value the worn item's contents over the one in their inventory. For example, I found that they'd try to go for a holstered pistol in their inventory over a sheathed zweihander (which will implode the game), so swapping it around so they're wearing the holstered pistol and carrying the sheathed sword in inventory works fine.

Screenshots

No response

Versions and configuration

- OS: Windows
    - OS Version: 10.0 2004
- Game Version: 00e0fc2 [64-bit]
- Graphics Version: Tiles
- Game Language:  []
- Mods loaded: [
    Bright Nights [bn],
    Disable NPC Needs [no_npc_food],
    Simplified Nutrition [novitamins],
    No Rail Stations [No_Rail_Stations],
    Elevated bridges [elevated_bridges]
]

Additional context

Discovered while testing #2930, it was quickly found out to be unrelated to the changes made and present in older builds.

Additionally tested in build 2023-06-03-2309 and got the same results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant