From 40d0d946a4a9cf90080698baf3ce5337a191ef47 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 12 Jun 2018 12:16:01 -0400 Subject: [PATCH] autogems: avoid crash with non-workshop links, add some logging Also update changelog, including revflood change Fixes #1303 --- docs/changelog.txt | 5 ++++- plugins/autogems.cpp | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 06ce97a6f..5877027cd 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -41,9 +41,12 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - Fixed ``-g`` flag (GDB) in Linux ``dfhack`` script (particularly on x64) - `autochop`, `autodump`, `autogems`, `automelt`, `autotrade`, `buildingplan`, `dwarfmonitor`, `fix-unit-occupancy`, `fortplan`, `stockflow`: fix issues with periodic tasks not working for some time after save/load cycles - `buildingplan`, `fortplan`: stop running before a world has fully loaded -- `autogems`: stop running repeatedly when paused +- `autogems`: + - stop running repeatedly when paused + - fixed crash when furnaces are linked to same stockpiles as jeweler's workshops - `ban-cooking`: fixed errors introduced by kitchen structure changes in 0.44.10-r1 - `remove-stress`: fixed an error when running on soul-less units (e.g. with ``-all``) +- `revflood`: stopped revealing tiles adjacent to tiles above open space inappropriately ## Misc Improvements - Added script name to messages produced by ``qerror()`` in Lua scripts diff --git a/plugins/autogems.cpp b/plugins/autogems.cpp index 3ec8d769b..b42d5bd16 100644 --- a/plugins/autogems.cpp +++ b/plugins/autogems.cpp @@ -136,10 +136,13 @@ void create_jobs() { std::set stockpiled; std::set unlinked; gem_map available; - auto workshops = &world->buildings.other[df::buildings_other_id::WORKSHOP_JEWELER]; - for (auto w = workshops->begin(); w != workshops->end(); ++w) { - auto workshop = virtual_cast(*w); + for (df::building *building : world->buildings.other[df::buildings_other_id::WORKSHOP_JEWELER]) { + auto workshop = virtual_cast(building); + if (!workshop) { + Core::printerr("autogems: invalid building %i (not a workshop)\n", building->id); + continue; + } auto links = workshop->profile.links.take_from_pile; if (workshop->construction_stage < 3) { @@ -167,11 +170,13 @@ void create_jobs() { } // Decrement current jobs from all linked workshops, not just this one. - auto outbound = stockpile->links.give_to_workshop; - for (auto ws = outbound.begin(); ws != outbound.end(); ++ws) { - auto shop = virtual_cast(*ws); - for (auto j = shop->jobs.begin(); j != shop->jobs.end(); ++j) { - auto job = *j; + for (auto bld : stockpile->links.give_to_workshop) { + auto shop = virtual_cast(bld); + if (!shop) { + // e.g. furnace + continue; + } + for (auto job : shop->jobs) { if (job->job_type == df::job_type::CutGems) { if (job->flags.bits.repeat) { piled[job->mat_index] = 0;