diff --git a/plugins/devel/eventExample.cpp b/plugins/devel/eventExample.cpp index b5f9d34d4..ba9c2a00d 100644 --- a/plugins/devel/eventExample.cpp +++ b/plugins/devel/eventExample.cpp @@ -175,8 +175,15 @@ void unitAttack(color_ostream& out, void* ptr) { EventManager::UnitAttackData* data = (EventManager::UnitAttackData*)ptr; out.print("unit %d attacks unit %d\n", data->attacker, data->defender); df::unit* defender = df::unit::find(data->defender); + if (!defender) { + out.printerr("defender %d does not exist\n", data->defender); + return; + } int32_t woundIndex = df::unit_wound::binsearch_index(defender->body.wounds, data->wound); - df::unit_wound* wound = defender->body.wounds[woundIndex]; + df::unit_wound* wound = vector_get(defender->body.wounds, woundIndex); + if (!wound) { + return; + } set parts; for ( auto a = wound->parts.begin(); a != wound->parts.end(); a++ ) { parts.insert((*a)->body_part_id);