]> git.seodisparate.com - EntityComponentMetaSystem/commitdiff
Fixed keepSomeMatchingFunctions
authorStephen Seo <seo.disparate@gmail.com>
Thu, 13 Jul 2017 08:28:45 +0000 (17:28 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 13 Jul 2017 08:28:45 +0000 (17:28 +0900)
Previous implementation would fail if functionIndex had wrapped around

src/EC/Manager.hpp

index fd7f8941c90f833d0adb90ffe35ce64a4008f74f..d3c297e50edc864dbf9b401b1866f5d1393d8be5 100644 (file)
@@ -664,12 +664,16 @@ namespace EC
         std::size_t keepSomeMatchingFunctions(List list)
         {
             std::size_t deletedCount = 0;
-            for(std::size_t i = 0; i < functionIndex; ++i)
+            for(auto iter = forMatchingFunctions.begin(); iter != forMatchingFunctions.end();)
             {
-                if(forMatchingFunctions.find(i) != forMatchingFunctions.end()
-                    && std::find(list.begin(), list.end(), i) == list.end())
+                if(std::find(list.begin(), list.end(), iter->first) == list.end())
                 {
-                    deletedCount += forMatchingFunctions.erase(i);
+                    iter = forMatchingFunctions.erase(iter);
+                    ++deletedCount;
+                }
+                else
+                {
+                    ++iter;
                 }
             }