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

fix: dont crash when equipping npc with no existing clothing #4356

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

ekaratzas
Copy link
Contributor

@ekaratzas ekaratzas commented Mar 15, 2024

Purpose of change

Fix crash when equipping armor to npc with no clothing.

Describe the solution

Crash due to accessing index 0 of empty std::vector. Skip accessing that vector in that corner-case.

Relevant backtrace


#0  operator() (__closure=0x7fffffffc4a0, index=0) at /home/gpf/gamedev/Cataclysm-BN/src/armor_layers.cpp:498
#1  0x00005555557180c9 in show_armor_layers_ui (who=...) at /home/gpf/gamedev/Cataclysm-BN/src/armor_layers.cpp:889
#2  0x000055555661c1b7 in game::npc_menu (this=this@entry=0x555558b3c190, who=...) at /home/gpf/gamedev/Cataclysm-BN/src/game.cpp:5383
#3  0x000055555661cded in game::examine (this=this@entry=0x555558b3c190, examp=...) at /home/gpf/gamedev/Cataclysm-BN/src/game.cpp:5534
#4  0x000055555661e0f3 in game::examine (this=this@entry=0x555558b3c190) at /usr/include/c++/11/optional:272
#5  0x00005555566ac11a in game::handle_action (this=this@entry=0x555558b3c190) at /home/gpf/gamedev/Cataclysm-BN/src/handle_action.cpp:1911
#6  0x0000555556622605 in game::do_turn (this=0x555558b3c190) at /home/gpf/gamedev/Cataclysm-BN/src/game.cpp:1450
#7  0x00005555555c9c84 in main (argc=0, argv=0x7fffffffe050) at /usr/include/c++/11/bits/unique_ptr.h:173

Describe alternatives you've considered

dda has a vastly different/rewritten? framework here.

Testing

take off all clothes/armor from npc.
try to equip armor from floor via sort armor menu.
no crash.
npc actually equips armor ok.

Additional context

Yes my compiler complained without that weird casting around nullopt.

Checklist

@github-actions github-actions bot added the src changes related to source code. label Mar 15, 2024
@scarf005 scarf005 self-requested a review March 15, 2024 06:46
@scarf005 scarf005 self-assigned this Mar 15, 2024
@KheirFerrum
Copy link
Collaborator

Copy link
Member

@scarf005 scarf005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024-03-15_16-02-09.mp4

@scarf005 scarf005 merged commit 508ea38 into cataclysmbnteam:main Mar 15, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
src changes related to source code.
Projects
None yet
3 participants