Switching firing modes with a gun equipped with a combat knife bayonet causes a crash.
Seems like the game is attempting to change to a "combat knife" firing mode that just doesn't work
first time reporting a bug ^.^
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)
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)
Can't reproduce anymore on official release 0.D-3479-g3233182 (or debug version from master).
Default (after loading save):

1st cycle (F):

2nd cycle (F):

3rd cycle (F):

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:
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.