diff --git a/include/Nazara/Core/HandledObject.inl b/include/Nazara/Core/HandledObject.inl index 9a7ebcc41..146e1fdd3 100644 --- a/include/Nazara/Core/HandledObject.inl +++ b/include/Nazara/Core/HandledObject.inl @@ -86,12 +86,11 @@ namespace Nz template HandledObject& HandledObject::operator=(HandledObject&& object) { - m_handles.reserve(m_handles.size() + object.m_handles.size()); - for (ObjectHandle* handle : object.m_handles) - { - m_handles.push_back(handle); + UnregisterAllHandles(); + + m_handles = std::move(object.m_handles); + for (ObjectHandle* handle : m_handles) handle->OnObjectMoved(static_cast(this)); - } return *this; } diff --git a/tests/Engine/Core/ObjectHandle.cpp b/tests/Engine/Core/ObjectHandle.cpp index 8fd8099fd..f5836ae81 100644 --- a/tests/Engine/Core/ObjectHandle.cpp +++ b/tests/Engine/Core/ObjectHandle.cpp @@ -90,13 +90,16 @@ SCENARIO("Handle", "[CORE][HandledObject][ObjectHandle]") Nz::ObjectHandle otherHandle = other.CreateHandle(); test = std::move(other); + THEN("Handles to previous objects should be invalid") + { + CHECK_FALSE(handle1.IsValid()); + CHECK_FALSE(handle2.IsValid()); + } + THEN("Handles should point to 4") { - CHECK(handle1->i == moveValue); - CHECK(handle2->i == moveValue); - CHECK(otherHandle->i == moveValue); - CHECK(handle1.GetObject() == &test); CHECK(otherHandle.GetObject() == &test); + CHECK(otherHandle->i == moveValue); } } }