From b7b32cfe26144d26d65dfb00854bd363c38b3a7d Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Sun, 18 Oct 2009 14:35:36 +0000 Subject: SCI: AvoidPath: skip polygons without vertices svn-id: r45223 --- engines/sci/engine/kpathing.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp index faba652f8a..9bca946882 100644 --- a/engines/sci/engine/kpathing.cpp +++ b/engines/sci/engine/kpathing.cpp @@ -1217,11 +1217,17 @@ static Polygon *convert_polygon(EngineState *s, reg_t polygon) { // Converts an SCI polygon into a Polygon // Parameters: (EngineState *) s: The game state // (reg_t) polygon: The SCI polygon to convert - // Returns : (Polygon *) The converted polygon + // Returns : (Polygon *) The converted polygon, or NULL on error SegManager *segMan = s->_segMan; int i; reg_t points = GET_SEL32(polygon, points); int size = GET_SEL32(polygon, size).toUint16(); + + if (size == 0) { + // If the polygon has no vertices, we skip it + return NULL; + } + Polygon *poly = new Polygon(GET_SEL32(polygon, type).toUint16()); int skip = 0; @@ -1379,8 +1385,11 @@ static PathfindingState *convert_polygon_set(EngineState *s, reg_t poly_list, Co if (dup == node) { // Polygon is not a duplicate, so convert it polygon = convert_polygon(s, node->value); - pf_s->polygons.push_back(polygon); - count += GET_SEL32(node->value, size).toUint16(); + + if (polygon) { + pf_s->polygons.push_back(polygon); + count += GET_SEL32(node->value, size).toUint16(); + } } node = s->_segMan->lookupNode(node->succ); @@ -1652,6 +1661,10 @@ reg_t kAvoidPath(EngineState *s, int argc, reg_t *argv) { case 3 : { reg_t retval; Polygon *polygon = convert_polygon(s, argv[2]); + + if (!polygon) + return NULL_REG; + // Override polygon type to prevent inverted result for contained access polygons polygon->type = POLY_BARRED_ACCESS; -- cgit v1.2.3