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 mutation examine window crash #71410

Merged
merged 2 commits into from
Feb 2, 2024

Conversation

gearhand
Copy link
Contributor

@gearhand gearhand commented Feb 1, 2024

Fixes #71237

Summary

Bugfixes "Made GetTrait function return std::nullopt_t in case of mutation_tab_mode::none"

Purpose of change

Fixes #71237

Describe the solution

GetTrait used to access passive vector when tab_mode is not 'active', which leads to a crash, if there are no mutations at all: tab_mode is 'none' and passive vec is empty.
At the same time GetTrait result is always assigned to 'examine_id' which is 'optional<trait_id>. So it seemed convenient to return empty optional in case of 'none' 'tab_mode'. Then calling code can handle it in correct way.

Describe alternatives you've considered

There was a proposition from @RenechCDDA to guard the call site with !passive.empty() check.

Testing

  1. Created new character without any traits and mutations.
  2. Opened mutation menu. Switch to 'Examine' mode.
  3. Checked that game didn't crash
  4. Created another character with some traits and one active mutation
  5. Checked that navigation works fine, switching to Examine mode and backwards works fine and also activation/deactivation of active mutation works fine too

Additional context

@github-actions github-actions bot added Info / User Interface Game - player communication, menus, etc. Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) new contributor labels Feb 1, 2024
src/mutation_ui.cpp Outdated Show resolved Hide resolved
src/mutation_ui.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Feb 1, 2024
gearhand and others added 2 commits February 1, 2024 23:40
Style fixes

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Feb 2, 2024
@Maleclypse Maleclypse merged commit b318d66 into CleverRaven:master Feb 2, 2024
26 checks passed
@Procyonae Procyonae added the 0.H Backport PR to backport to the 0.H stable release canddiate label May 20, 2024
Procyonae pushed a commit to Procyonae/Cataclysm-DDA that referenced this pull request May 20, 2024
* Fix mutation examine window crash

Fixes CleverRaven#71237

* Apply suggestions from code review

Style fixes

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@Procyonae Procyonae mentioned this pull request May 20, 2024
Maleclypse added a commit that referenced this pull request May 21, 2024
@Procyonae Procyonae added 0.H Backported and removed 0.H Backport PR to backport to the 0.H stable release canddiate labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.H Backported astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Info / User Interface Game - player communication, menus, etc. json-styled JSON lint passed, label assigned by github actions Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies new contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access to empty container bug exists in function "GetTrait"
3 participants