Cataclysm-dda: Combat Knife bayonet crashing

Created on 20 May 2019  Â·  14Comments  Â·  Source: CleverRaven/Cataclysm-DDA

Describe the bug

Switching firing modes with a gun equipped with a combat knife bayonet causes a crash.

Steps To Reproduce

  1. Equip a loaded gun with a combat knife bayonet
  2. Enter the firing menu
  3. Cycle through all the firing modes

Expected behavior

Seems like the game is attempting to change to a "combat knife" firing mode that just doesn't work

Versions and configuration

  • OS: Windows [64-bit]
  • Game Version: 0.D-3197-gda3edc5
  • Graphics Version: Tiles
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Craftable Gun Pack [craftgp],
    DeadLeaves' Fictional Guns [FIC_Weapons],
    Extended Realistic Guns [realguns],
    Garden Pots [growable-pots],
    Makeshift Items Mod [makeshift],
    Medieval and Historic Content [Medieval_Stuff],
    More Survival Tools [More_Survival_Tools],
    Mythological Replicas [nw_pack],
    Modular Turrets [modular_turrets],
    Salvaged Robots [Salvaged_Robots],
    DinoMod [DinoMod],
    Alternative Map Key [alt_map_key],
    Hydroponics [hydroponics],
    Mutant NPCs [mutant_npcs],
    Boats [boats],
    Folding Parts pack [deoxymod],
    Vehicle Additions Pack [blazemod],
    Tanks and Other Vehicles [Tanks],
    No Fungal Monsters [No_Fungi],
    Classes and Scenarios Mod [more_classes_scenarios],
    Classic Roguelike Classes [RL_Classes],
    Safe Autodoc [safeautodoc],
    StatsThroughSkills [StatsThroughSkills]
    ]

Additional context

first time reporting a bug ^.^

Crash log

crash.log

(S2 - Confirmed) <Crash / Freeze> Gunmod / Toolmod

All 14 comments

Similar issue here, tough on mode switch, i first get a pop up window saying:

MinGW Runtime Assertion

Assertion failed!

Program: C:\GamesCDDA\cataclysm-tiles.exe
File: src/optional.h, Line 45
Expression: full

Abort Retry Ignore

Then on retry or abort, (you cannot ignore, window just comes instantly back up) i get the crash log (attached)

  • OS: Windows [64-bit]
  • Game Version: 0.D-3311-g5147b3c
  • Graphics Version: Tiles
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Icecoon's Arsenal [ew_pack],
    Makeshift Items Mod [makeshift],
    Medieval and Historic Content [Medieval_Stuff],
    More Survival Tools [More_Survival_Tools],
    Mutant NPCs [mutant_npcs],
    Folding Parts pack [deoxymod],
    Vehicle Additions Pack [blazemod],
    Tanks and Other Vehicles [Tanks],
    Disable Religious Texts [no_religious_Texts],
    Crazy Cataclysm [crazy_cataclysm]
    ]

Tested on a fresh world\game\character with spawning in the items and then targeting nearby enemy and attempting to change firing mode.

Shouldn't matter but, specifically i spawned an AK47, magazine and ammo for it, loaded it in, then attaching the combat knife.
Tried attaching the save file, which as far as i understand is the world file. (only one char in there, ready to test with mentioned equips)

crash.log

Alt mapkey.zip

Can't reproduce anymore on official release 0.D-3479-g3233182 (or debug version from master).

  • Load save file from @EternalHunter777
  • Cycle through firing mode with SHIFT + f

Default (after loading save):

image

  • 1st cycle (F):
    image

  • 2nd cycle (F):
    image

  • 3rd cycle (F):
    image

Note: as a side note, and unless I'm mistaken, there's no more a "cycle firing mode" menu in the firing menu (f).

@neitsa You are correct in that using shift-f to choose mode between SAFACombat knife bayonet does not crash the game.

However, entering the targeting UI, by just hitting "f", and THEN changing fire-mode by just hitting "s" it will crash when it should cycle to combat knife mode.
The cycle as i call it, is just the eternal changing between fire modes, whatever they may be.
For this weapon it is Semi Auto - Bayonet - Full Auto.

The fault here was with me not describing the exact reproducible way, as i believed the OP had done so.

Oh ok, thanks for the precision! No problem, I wasn't sure how to cycle in the firing menu since I never use it from there.

I'll test exactly as you mentioned. Thanks a lot!

Got a repro (and this time I could see the [s] switch firing mode in the firing menu...)

It's an assert:

https://github.com/CleverRaven/Cataclysm-DDA/blob/f4c1c1c3ca1ce9eb7663193213cf77b1ffe2354f/src/optional.h#L44-L47

full is false which triggers the assert and data is completely uninitialized.

The stack trace:

    ucrtbased.dll!common_assert_to_message_box<wchar_t>(const wchar_t * const expression, const wchar_t * const file_name, const unsigned int line_number, void * const return_address) Line 388    C++
    ucrtbased.dll!common_assert<wchar_t>(const wchar_t * const expression, const wchar_t * const file_name, const unsigned int line_number, void * const return_address) Line 424   C++
    ucrtbased.dll!_wassert(const wchar_t * expression, const wchar_t * file_name, unsigned int line_number) Line 444    C++
>   Cataclysm-App-Debug-x64.exe!cata::optional<islot_gun>::get() Line 45    C++
    Cataclysm-App-Debug-x64.exe!cata::optional<islot_gun>::operator->() Line 104    C++
    Cataclysm-App-Debug-x64.exe!time_to_fire(const Character & p, const itype & firing) Line 2047   C++
    Cataclysm-App-Debug-x64.exe!print_ranged_chance(const player & p, const catacurses::window & w, int line_number, target_mode mode, input_context & ctxt, const item & ranged_weapon, const dispersion_sources & dispersion, const std::vector<confidence_rating,std::allocator<confidence_rating> > & confidence_config, double range, double target_size, int recoil) Line 895 C++
    Cataclysm-App-Debug-x64.exe!print_aim(const player & p, const catacurses::window & w, int line_number, input_context & ctxt, item * weapon, const double target_size, const tripoint & pos, double predicted_recoil) Line 967   C++
    Cataclysm-App-Debug-x64.exe!target_handler::target_ui(player & pc, target_mode mode, item * relevant, int range, const itype * ammo, const std::function<itype const * __cdecl(item *)> & on_mode_change, const std::function<itype const * __cdecl(item *)> & on_ammo_change) Line 1387    C++
    Cataclysm-App-Debug-x64.exe!target_handler::target_ui(player & pc, const targeting_data & args) Line 1028   C++
    Cataclysm-App-Debug-x64.exe!game::plfire() Line 7939    C++
    Cataclysm-App-Debug-x64.exe!game::plfire(item & weapon, int bp_cost) Line 7993  C++
    Cataclysm-App-Debug-x64.exe!fire() Line 1205    C++
    Cataclysm-App-Debug-x64.exe!game::handle_action() Line 1827 C++
    Cataclysm-App-Debug-x64.exe!game::do_turn() Line 1422   C++
    Cataclysm-App-Debug-x64.exe!SDL_main(int argc, char * * argv) Line 689  C++
    Cataclysm-App-Debug-x64.exe!main_getcmdline(...) Line 177   C
    [External Code]

I'll try to understand what's happening.

From just reading the stack trace I'd guess that a combat bayonet isn't a gun and therefore islot_gun is a cata::nullopt. The optional is however dereferenced when cycling through firing modes which expects everything to be a gun, which causes the assert to fail.

Just realized that's probably pretty obvious but posting anyways cause why not. ¯\_(ツ)_/¯

Not at all @ifreund, it wasn't obvious to me :| Thanks a lot for posting this otherwise I'd still be digging!

I'm not really sure how to fix this though... Would removing the bayonet / combat knife from the firing modes would be an acceptable patch?

Yeah I think that cycling fire modes from the target ui should skip melee firing modes, since those can't be used from that ui afaik. The should still be part of firing modes outside of that ui though I think.

Added a fix, it seems to correctly handle the problem. (bugged fix).

Great! 💯

intermittent heisenbug, apparently caused by bayonet style weapons intermittently returning true from item::is_gun() and then crashing when trying to actually access item::type->gun because they're not a gun.

Should be fixed by #35102.

This issue is still reproducible in current master.

The issue stems from the fact that bayonets straddle a very weird line between islot_mod and islot_gunmod and many functions involving using a firearm alternate between checking the two as if they were the same (or always guaranteed to be together) which they currently are not.

That was completely wrong, but I found the real problem anyways.

Was this page helpful?
0 / 5 - 0 ratings