diff --git a/docs/changelog.txt b/docs/changelog.txt index 9c93adfd57..71a48becc1 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -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 diff --git a/plugins/getplants.cpp b/plugins/getplants.cpp index 87f1c0e76c..fe72bd3b1e 100644 --- a/plugins/getplants.cpp +++ b/plugins/getplants.cpp @@ -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; @@ -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)) { @@ -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;