Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Template for new versions:
- `buildingplan`: restore planner UI elements: hollow constructions, only engraved slabs, only empty cages, weapon count

## Misc Improvements
- `EventManager`: add safety check to potentially avoid a DFHack crash when DF's ``reports`` table is out of order

## Documentation

Expand Down
5 changes: 5 additions & 0 deletions library/modules/EventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,11 @@ static void manageUnitAttackEvent(color_ostream& out) {
multimap<Plugin*,EventHandler> copy(handlers[EventType::UNIT_ATTACK].begin(), handlers[EventType::UNIT_ATTACK].end());
std::vector<df::report*>& reports = df::global::world->status.reports;
size_t idx = df::report::binsearch_index(reports, lastReportUnitAttack, false);
if (idx >= reports.size())
{
WARN(log, out).print("manageUnitAttackEvent: last reported unit attack lookup failed ({} -> {})\n", lastReportUnitAttack, idx);
return;
}
// returns the index to the key equal to or greater than the key provided
idx = reports[idx]->id == lastReportUnitAttack ? idx + 1 : idx; // we need the index after (where the new stuff is)

Expand Down
Loading