diff --git a/src/entt/graph/adjacency_matrix.hpp b/src/entt/graph/adjacency_matrix.hpp index ea4a7b43c..5ece5ab00 100644 --- a/src/entt/graph/adjacency_matrix.hpp +++ b/src/entt/graph/adjacency_matrix.hpp @@ -274,7 +274,7 @@ public: * @brief Exchanges the contents with those of a given adjacency matrix. * @param other Adjacency matrix to exchange the content with. */ - void swap(adjacency_matrix &other) { + void swap(basic_adjacency_matrix &other) { using std::swap; swap(matrix, other.matrix); swap(vert, other.vert); @@ -335,8 +335,13 @@ public: * @param vertices The new number of vertices. */ void resize(const size_type vertices) { - matrix.resize(vertices * vertices); - vert = vertices; + basic_adjacency_matrix other{vertices, get_allocator()}; + + for(auto [lhs, rhs]: edges()) { + other.insert(lhs, rhs); + } + + other.swap(*this); } /** diff --git a/test/entt/graph/adjacency_matrix.cpp b/test/entt/graph/adjacency_matrix.cpp index 2b0ef5f95..66b797c52 100644 --- a/test/entt/graph/adjacency_matrix.cpp +++ b/test/entt/graph/adjacency_matrix.cpp @@ -6,15 +6,15 @@ TEST(AdjacencyMatrix, Resize) { entt::adjacency_matrix adjacency_matrix{2}; - adjacency_matrix.insert(0u, 1u); + adjacency_matrix.insert(1u, 0u); ASSERT_EQ(adjacency_matrix.size(), 2u); - ASSERT_TRUE(adjacency_matrix.contains(0u, 1u)); + ASSERT_TRUE(adjacency_matrix.contains(1u, 0u)); adjacency_matrix.resize(3u); ASSERT_EQ(adjacency_matrix.size(), 3u); - ASSERT_TRUE(adjacency_matrix.contains(0u, 1u)); + ASSERT_TRUE(adjacency_matrix.contains(1u, 0u)); } TEST(AdjacencyMatrix, Constructors) {