diff --git a/src/p_tags.cpp b/src/p_tags.cpp index e773b691fc..851c4ee94d 100644 --- a/src/p_tags.cpp +++ b/src/p_tags.cpp @@ -309,13 +309,24 @@ int FSectorTagIterator::Next() ret = start; start = -1; } - else + else if (searchtag != 0) { while (start >= 0 && tagManager.allTags[start].tag != searchtag) start = tagManager.allTags[start].nexttag; if (start == -1) return -1; ret = tagManager.allTags[start].target; start = tagManager.allTags[start].nexttag; } + else + { + // with the tag manager, searching for tag 0 has to be different, because it won't create entries for untagged sectors. + while (start < numsectors && tagManager.SectorHasTags(start)) + { + start++; + } + if (start == numsectors) return -1; + ret = start; + start++; + } return ret; } diff --git a/src/p_tags.h b/src/p_tags.h index 2195821c15..75d397d8d3 100644 --- a/src/p_tags.h +++ b/src/p_tags.h @@ -79,7 +79,7 @@ public: FSectorTagIterator(int tag) { searchtag = tag; - start = tagManager.TagHashFirst[((unsigned int)tag) % FTagManager::TAG_HASH_SIZE]; + start = tag == 0 ? 0 : tagManager.TagHashFirst[((unsigned int)tag) % FTagManager::TAG_HASH_SIZE]; } // Special constructor for actions that treat tag 0 as 'back of activation line'