Skip to content

Commit a8b8a4f

Browse files
authored
Merge pull request #4172 from myk002/myk_badplants
[getplants] protect against invalid basic materials
2 parents 0dda652 + 9b326bb commit a8b8a4f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Template for new versions:
6363
- `sort`: fix potential crash when removing jobs directly from the Tasks info screen
6464
- `misery`: fix error when changing the misery factor
6565
- When passing map movement keys through to the map from DFHack tool windows, also pass fast z movements (shift-scroll by default)
66+
- `getplants`: fix crash when processing mod-added plants with invalid materials
6667

6768
## Misc Improvements
6869
- `autochop`: better error output when target burrows are not specified on the commandline

plugins/getplants.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ enum class selectability {
7474
// result in the plants not being usable for farming or even collectable at all).
7575

7676
selectability selectablePlant(color_ostream& out, const df::plant_raw* plant, bool farming) {
77+
TRACE(log, out).print("analyzing %s\n", plant->id.c_str());
7778
const DFHack::MaterialInfo basic_mat = DFHack::MaterialInfo(plant->material_defs.type[plant_material_def::basic_mat], plant->material_defs.idx[plant_material_def::basic_mat]);
7879
bool outOfSeason = false;
7980
selectability result = selectability::Nonselectable;
@@ -96,8 +97,10 @@ selectability selectablePlant(color_ostream& out, const df::plant_raw* plant, bo
9697
return selectability::Nonselectable;
9798
}
9899

99-
if (basic_mat.material->flags.is_set(material_flags::EDIBLE_RAW) ||
100-
basic_mat.material->flags.is_set(material_flags::EDIBLE_COOKED)) {
100+
if (basic_mat.isValid() &&
101+
(basic_mat.material->flags.is_set(material_flags::EDIBLE_RAW) ||
102+
basic_mat.material->flags.is_set(material_flags::EDIBLE_COOKED)))
103+
{
101104
DEBUG(log, out).print("%s is edible\n", plant->id.c_str());
102105
if (farming) {
103106
if (basic_mat.material->flags.is_set(material_flags::EDIBLE_RAW)) {
@@ -123,8 +126,10 @@ selectability selectablePlant(color_ostream& out, const df::plant_raw* plant, bo
123126
}
124127
}
125128

126-
if (basic_mat.material->reaction_product.id.size() > 0 ||
127-
basic_mat.material->reaction_class.size() > 0) {
129+
if (basic_mat.isValid() &&
130+
(basic_mat.material->reaction_product.id.size() > 0 ||
131+
basic_mat.material->reaction_class.size() > 0))
132+
{
128133
DEBUG(log, out).print("%s has a reaction\n", plant->id.c_str());
129134
if (farming) {
130135
result = selectability::Selectable;

0 commit comments

Comments
 (0)