I use ENTT and add the following component to every entity.
template<typename T, typename... Args>
T& AddComponent(Args&&... args)
{
HZ_CORE_ASSERT(!HasComponent<T>(), "Entity already has component!");
T& component = m_Scene->m_Registry.emplace<T>(m_EntityHandle, std::forward<Args>(args)...);
m_Scene->OnComponentAdded<T>(*this, component);
return component;
}
struct TagComponent
{
std::string Tag;
TagComponent() = default;
TagComponent(const TagComponent& other) : Tag(other.Tag) {};
TagComponent(const std::string tag) : Tag(tag) {}
};
Sometimes it will throw "access violation exception" when _Container_base12::_Orphan_all() is called during reallocation. I find that the address for the two pointers in std::Container_proxy is weird. _Mycont should have one byte more for the address to make sense. _Myfirstiter should not have the byte 0xfd at the front, it should be a nullptr.
What's the possible reason?
Edit: Failed to solve this bug. It's really weired that if I put a breakpoint and run step by step when I load the node[0]-1 of the mesh, the bug never occur. Otherwise it came up with a possibility of about 20%.