Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/frontend/StarCharCreation.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-29 22:02:35 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-29 22:02:35 +1000
commit7fc9260829453b306e27853207e8efbd7d6f8a8d (patch)
treeaed363d72b768006619a08730d917b425cd73a55 /source/frontend/StarCharCreation.cpp
parentdc134e168bd04d39f8a30819ba3a0b00bb8ae1cb (diff)
Add extra checks to the char creation pane to prevent crashes when the player is not using an extension mod with extra species
Diffstat (limited to 'source/frontend/StarCharCreation.cpp')
-rw-r--r--source/frontend/StarCharCreation.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/source/frontend/StarCharCreation.cpp b/source/frontend/StarCharCreation.cpp
index 7d05712..d873a72 100644
--- a/source/frontend/StarCharCreation.cpp
+++ b/source/frontend/StarCharCreation.cpp
@@ -269,15 +269,19 @@ void CharCreationPane::changed() {
fetchChild<LabelWidget>("labelPortrait")->setText(labels[8]);
fetchChild<LabelWidget>("labelPersonality")->setText(labels[9]);
- fetchChild<ButtonWidget>(strf("species.{}", m_speciesChoice))->check();
- fetchChild<ButtonWidget>(strf("gender.{}", genderIdx))->check();
+ if (auto speciesButton = fetchChild<ButtonWidget>(strf("species.{}", m_speciesChoice)))
+ speciesButton->check();
+ if (auto genderButton = fetchChild<ButtonWidget>(strf("gender.{}", genderIdx)))
+ genderButton->check();
+
auto modeButton = fetchChild<ButtonWidget>(strf("mode.{}", m_modeChoice));
modeButton->check();
setLabel("labelMode", modeButton->data().getString("description", "fail"));
// Update the gender images for the new species
for (size_t i = 0; i < species.genderOptions.size(); i++)
- fetchChild<ButtonWidget>(strf("gender.{}", i))->setOverlayImage(species.genderOptions[i].image);
+ if (auto button = fetchChild<ButtonWidget>(strf("gender.{}", i)))
+ button->setOverlayImage(species.genderOptions[i].image);
for (auto const& nameDefPair : root.speciesDatabase()->allSpecies()) {
String name;
@@ -286,8 +290,7 @@ void CharCreationPane::changed() {
// NOTE: Probably not hot enough to matter, but this contains and indexOf makes this loop
// O(n^2). This is less than ideal.
if (m_speciesList.contains(name)) {
- auto bw = fetchChild<ButtonWidget>(strf("species.{}", m_speciesList.indexOf(name)));
- if (bw)
+ if (auto bw = fetchChild<ButtonWidget>(strf("species.{}", m_speciesList.indexOf(name))))
bw->setOverlayImage(def->options().genderOptions[genderIdx].characterImage);
}
}