Michele Caini 8 년 전
부모
커밋
31a18da578
2개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      src/entt/entity/sparse_set.hpp
  2. 9 0
      test/entt/entity/registry.cpp

+ 3 - 1
src/entt/entity/sparse_set.hpp

@@ -533,7 +533,9 @@ public:
      */
     void destroy(entity_type entity) override {
         // swapping isn't required here, we are getting rid of the last element
-        instances[underlying_type::get(entity)] = std::move(instances.back());
+        // however, we must protect ourselves from self assignments (see #37)
+        auto tmp = std::move(instances.back());
+        instances[underlying_type::get(entity)] = std::move(tmp);
         instances.pop_back();
         underlying_type::destroy(entity);
     }

+ 9 - 0
test/entt/entity/registry.cpp

@@ -1,3 +1,4 @@
+#include <unordered_set>
 #include <functional>
 #include <gtest/gtest.h>
 #include <entt/entity/registry.hpp>
@@ -435,3 +436,11 @@ TEST(DefaultRegistry, SortMulti) {
         ASSERT_EQ(registry.get<int>(entity), ival++);
     }
 }
+
+TEST(DefaultRegistry, ComponentsWithTypesFromStandardTemplateLibrary) {
+    // see #37 - the test shouldn't crash, that's all
+    entt::DefaultRegistry registry;
+    auto entity = registry.create();
+    registry.assign<std::unordered_set<int>>(entity).insert(42);
+    registry.destroy(entity);
+}