Skip to content

Commit

Permalink
protect against invalid basic materials
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jan 14, 2024
1 parent 0dda652 commit 9b326bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Template for new versions:
- `sort`: fix potential crash when removing jobs directly from the Tasks info screen
- `misery`: fix error when changing the misery factor
- When passing map movement keys through to the map from DFHack tool windows, also pass fast z movements (shift-scroll by default)
- `getplants`: fix crash when processing mod-added plants with invalid materials

## Misc Improvements
- `autochop`: better error output when target burrows are not specified on the commandline
Expand Down
13 changes: 9 additions & 4 deletions plugins/getplants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ enum class selectability {
// result in the plants not being usable for farming or even collectable at all).

selectability selectablePlant(color_ostream& out, const df::plant_raw* plant, bool farming) {
TRACE(log, out).print("analyzing %s\n", plant->id.c_str());
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]);
bool outOfSeason = false;
selectability result = selectability::Nonselectable;
Expand All @@ -96,8 +97,10 @@ selectability selectablePlant(color_ostream& out, const df::plant_raw* plant, bo
return selectability::Nonselectable;
}

if (basic_mat.material->flags.is_set(material_flags::EDIBLE_RAW) ||
basic_mat.material->flags.is_set(material_flags::EDIBLE_COOKED)) {
if (basic_mat.isValid() &&
(basic_mat.material->flags.is_set(material_flags::EDIBLE_RAW) ||
basic_mat.material->flags.is_set(material_flags::EDIBLE_COOKED)))
{
DEBUG(log, out).print("%s is edible\n", plant->id.c_str());
if (farming) {
if (basic_mat.material->flags.is_set(material_flags::EDIBLE_RAW)) {
Expand All @@ -123,8 +126,10 @@ selectability selectablePlant(color_ostream& out, const df::plant_raw* plant, bo
}
}

if (basic_mat.material->reaction_product.id.size() > 0 ||
basic_mat.material->reaction_class.size() > 0) {
if (basic_mat.isValid() &&
(basic_mat.material->reaction_product.id.size() > 0 ||
basic_mat.material->reaction_class.size() > 0))
{
DEBUG(log, out).print("%s has a reaction\n", plant->id.c_str());
if (farming) {
result = selectability::Selectable;
Expand Down

0 comments on commit 9b326bb

Please sign in to comment.