]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/intrusivelist.qh
Remove legacy Quake bbox expansion: map entities
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / intrusivelist.qh
index 3dee9ca38823011ee7fc27313efcf23d01480f4e..385f7b3b13282edb9deb40f0252d679923f3c8ff 100644 (file)
@@ -188,6 +188,8 @@ void IL_REMOVE(IntrusiveList this, entity it)
                assert(_il); \
                .entity il_next = _il.il_nextfld; \
                noref int i = 0; \
+               entity il_loop_item_save = this.il_loop_item; \
+               this.il_loop_item = NULL; \
                for (entity _next, _it = _il.il_head; _it; (_it = _next, ++i)) \
                { \
                        const noref entity it = _it; \
@@ -199,7 +201,7 @@ void IL_REMOVE(IntrusiveList this, entity it)
                        else \
                                _next = it.(il_next); /* in case next item has changed */ \
                } \
-               this.il_loop_item = NULL; \
+               this.il_loop_item = il_loop_item_save; \
        MACRO_END
 
 .int il_id;
@@ -272,9 +274,12 @@ void IL_ENDFRAME()
 // it should be used only in very particular cases such as after a copyentity call
 void IL_REMOVE_RAW(entity it)
 {
-       it.il_lists = '0 0 0';
-       for (int i = 0; i < IL_MAX * 2; ++i)
-               it.il_links_flds[i] = nil;
+       if (it.il_lists)
+       {
+               it.il_lists = '0 0 0';
+               for (int i = 0; i < IL_MAX * 2; ++i)
+                       it.il_links_flds[i] = nil;
+       }
 }
 
 // called when an entity is deleted with delete() / remove()
@@ -343,6 +348,25 @@ TEST(intrusivelist, ModificationsWhileLooping)
        });
        EXPECT_TRUE(s == "1234");
 
+       IL_TEST_BUILD();
+       IL_EACH(il_test, true,
+       {
+               s = strcat(s, it.classname);
+               if (it == ent2)
+                       IL_EACH(il_test, true,
+                       {
+                               s = strcat(s, it.classname);
+                               if (it == ent3)
+                                       IL_EACH(il_test, true,
+                                       {
+                                               s = strcat(s, it.classname);
+                                       });
+                               if (it == ent4)
+                                       break;
+                       });
+       });
+       EXPECT_TRUE(s == "12123123454345");
+
        IL_DELETE(il_test);
        delete(ent1); delete(ent2); delete(ent3); delete(ent4); delete(ent5);