From d6f48dbd913f3b982a62bd653bbb8f0d11314467 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 8 Oct 2016 18:02:34 +0000 Subject: [PATCH] Prevent crash when level specifies invalid wall number Kreator reports that "Pyramids of Luxoran" crashes due to a valptridx sanity check. The level incorrectly attempts to open a wall on a segment/side which has no wall. Add an error check and a con_printf suggesting that the level author needs to fix the invalid trigger. --- similar/main/switch.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/similar/main/switch.cpp b/similar/main/switch.cpp index 31c219a68..ef03ee2b5 100644 --- a/similar/main/switch.cpp +++ b/similar/main/switch.cpp @@ -173,7 +173,16 @@ static int do_change_walls(const trigger &t, const uint8_t new_wall_type) Assert(cside != side_none); } - auto &wall0 = *vwallptr(segp->sides[side].wall_num); + wall *w0p; + try { + const auto w0num = segp->sides[side].wall_num; + w0p = vwallptr(w0num); + } catch (const valptridx::index_range_exception &e) { + con_puts(CON_URGENT, e.what()); + con_printf(CON_URGENT, "%s:%u: trigger %p link %u tried to open segment %hu, side %u which is an invalid wall; ignoring. Please report this to the level author, not to the Rebirth maintainers.", __FILE__, __LINE__, addressof(t), i, static_cast(segp), side); + continue; + } + auto &wall0 = *w0p; wallptr_t wall1 = nullptr; if ((cside == side_none || csegp->sides[cside].wall_num == wall_none || (wall1 = vwallptr(csegp->sides[cside].wall_num))->type == new_wall_type) &&