From 42c541012c3ba8a58b9441b6bc38f9b15d1dabc1 Mon Sep 17 00:00:00 2001 From: Vasilii Rogin Date: Tue, 23 May 2023 23:50:37 +0300 Subject: [PATCH] Fix crash in _map_age_dead_critters (#258) Co-authored-by: Alexander Batalov --- src/object.cc | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/object.cc b/src/object.cc index 60b3bd3..a597a76 100644 --- a/src/object.cc +++ b/src/object.cc @@ -2133,27 +2133,18 @@ Object* objectFindFirst() { gObjectFindElevation = 0; - ObjectListNode* objectListNode; for (gObjectFindTile = 0; gObjectFindTile < HEX_GRID_SIZE; gObjectFindTile++) { - objectListNode = gObjectListHeadByTile[gObjectFindTile]; - if (objectListNode) { - break; + ObjectListNode* objectListNode = gObjectListHeadByTile[gObjectFindTile]; + while (objectListNode != NULL) { + Object* object = objectListNode->obj; + if (!artIsObjectTypeHidden(FID_TYPE(object->fid))) { + gObjectFindLastObjectListNode = objectListNode; + return object; + } + objectListNode = objectListNode->next; } } - if (gObjectFindTile == HEX_GRID_SIZE) { - gObjectFindLastObjectListNode = NULL; - return NULL; - } - - while (objectListNode != NULL) { - if (artIsObjectTypeHidden(FID_TYPE(objectListNode->obj->fid)) == 0) { - gObjectFindLastObjectListNode = objectListNode; - return objectListNode->obj; - } - objectListNode = objectListNode->next; - } - gObjectFindLastObjectListNode = NULL; return NULL; } @@ -2167,9 +2158,14 @@ Object* objectFindNext() ObjectListNode* objectListNode = gObjectFindLastObjectListNode->next; - while (gObjectFindTile < HEX_GRID_SIZE) { + while (true) { if (objectListNode == NULL) { - objectListNode = gObjectListHeadByTile[gObjectFindTile++]; + gObjectFindTile++; + if (gObjectFindTile >= HEX_GRID_SIZE) { + break; + } + + objectListNode = gObjectListHeadByTile[gObjectFindTile]; } while (objectListNode != NULL) { @@ -2219,9 +2215,14 @@ Object* objectFindNextAtElevation() ObjectListNode* objectListNode = gObjectFindLastObjectListNode->next; - while (gObjectFindTile < HEX_GRID_SIZE) { + while (true) { if (objectListNode == NULL) { - objectListNode = gObjectListHeadByTile[gObjectFindTile++]; + gObjectFindTile++; + if (gObjectFindTile >= HEX_GRID_SIZE) { + break; + } + + objectListNode = gObjectListHeadByTile[gObjectFindTile]; } while (objectListNode != NULL) {