У меня есть static static std::unordered_map, по какой-то причине в конце программы некоторые классы внутри карты выдают ошибку при автоматическом уничтожении:
Invalid address specified to RtlValidateHeap( 0000027D28B70000, 0000027D28BA5BA8 )
После некоторого тестирования я обнаружил, что это происходит только в том случае, если класс принадлежит родительскому классу, содержащему виртуальную функцию. Есть ли способ исправить это или обойти это?
Это часть моего кода:
main.cpp
#include
class Parent
{
public:
virtual int function(){
return -1;
}
};
class Child : public Parent, public Harmony::Core::Object
{
public:
Child(uint64_t uuid) :
Harmony::Core::Object(uuid, this) {};
int function(){
return 0;
}
};
int main()
{
Child::create(NULL); // create a child class and store it in an static inline map
}
Object.h
#pragma once
#include
#include
#include
#include
#include
#include
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Header
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Harmony
{
namespace Core
{
template
class Object
{
public:
typedef std::unique_ptr Pointer;
public:
Object(const uint64_t& uuid, Type* pointer);
~Object();
const uint64_t getUUID();
static Type& find(const uint64_t& uuid);
static Type& create(const uint64_t& uuid);
static void add(std::unique_ptr pointer);
static void rmv(const uint64_t& uuid);
static const uint64_t randomUUID();
protected:
static const uint64_t assignUUID(const uint64_t uuid);
protected:
const uint64_t m_uuid;
static inline std::unordered_map m_pointers;
static inline std::unordered_map m_objects;
};
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template
inline Harmony::Core::Object::Object(const uint64_t& uuid, Type* pointer) :
Harmony::Core::Object::m_uuid(Harmony::Core::Object::assignUUID(uuid))
{
Harmony::Core::Object::m_pointers[Harmony::Core::Object::m_uuid] = pointer;
}
template
inline Harmony::Core::Object::~Object()
{
assert(Harmony::Core::Object::m_pointers.contains(Harmony::Core::Object::m_uuid));
Harmony::Core::Object::m_pointers.erase(Harmony::Core::Object::m_uuid);
}
template
inline const uint64_t Harmony::Core::Object::getUUID()
{
return Harmony::Core::Object::m_uuid;
}
template
inline Type& Harmony::Core::Object::find(const uint64_t& uuid)
{
assert(Harmony::Core::Object::m_pointers.contains(uuid));
return *Harmony::Core::Object::m_pointers[uuid];
}
template
inline Type& Harmony::Core::Object::create(const uint64_t& uuid)
{
std::unique_ptr pointer = std::make_unique(uuid);
Type& reference = *pointer;
Harmony::Core::Object::add(std::move(pointer));
return reference;
}
template
inline void Harmony::Core::Object::add(std::unique_ptr pointer)
{
const uint64_t& uuid(pointer->getUUID());
assert(!Harmony::Core::Object::m_objects.contains(uuid));
Harmony::Core::Object::m_objects[uuid] = std::move(pointer);
}
template
inline void Harmony::Core::Object::rmv(const uint64_t& uuid)
{
assert(Harmony::Core::Object::m_pointers.contains(uuid));
if (Harmony::Core::Object::m_objects.contains(uuid))
Harmony::Core::Object::m_objects.erase(uuid);
if (Harmony::Core::Object::m_pointers.contains(uuid))
Harmony::Core::Object::m_pointers.erase(uuid);
}
template
inline const uint64_t Harmony::Core::Object::randomUUID()
{
static std::random_device randomDevice;
static std::mt19937_64 engine(randomDevice());
static std::uniform_int_distribution uniformDistribution;
return uniformDistribution(engine);
}
template
inline const uint64_t Harmony::Core::Object::assignUUID(const uint64_t uuid)
{
uint64_t index(uuid);
while (index == NULL or Harmony::Core::Object::m_pointers.contains(index))
index = Harmony::Core::Object::randomUUID();
return index;
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -at-the-en
Статический встроенный std::map не может удалить класс, содержащий виртуальную функцию в конце программы. ⇐ C++
Программы на C++. Форум разработчиков
1727824196
Anonymous
У меня есть static static std::unordered_map, по какой-то причине в конце программы некоторые классы внутри карты выдают ошибку при автоматическом уничтожении:
Invalid address specified to RtlValidateHeap( 0000027D28B70000, 0000027D28BA5BA8 )
После некоторого тестирования я обнаружил, что это происходит только в том случае, если класс принадлежит родительскому классу, содержащему виртуальную функцию. Есть ли способ исправить это или обойти это?
Это часть моего кода:
main.cpp
#include
class Parent
{
public:
virtual int function(){
return -1;
}
};
class Child : public Parent, public Harmony::Core::Object
{
public:
Child(uint64_t uuid) :
Harmony::Core::Object(uuid, this) {};
int function(){
return 0;
}
};
int main()
{
Child::create(NULL); // create a child class and store it in an static inline map
}
Object.h
#pragma once
#include
#include
#include
#include
#include
#include
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Header
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Harmony
{
namespace Core
{
template
class Object
{
public:
typedef std::unique_ptr Pointer;
public:
Object(const uint64_t& uuid, Type* pointer);
~Object();
const uint64_t getUUID();
static Type& find(const uint64_t& uuid);
static Type& create(const uint64_t& uuid);
static void add(std::unique_ptr pointer);
static void rmv(const uint64_t& uuid);
static const uint64_t randomUUID();
protected:
static const uint64_t assignUUID(const uint64_t uuid);
protected:
const uint64_t m_uuid;
static inline std::unordered_map m_pointers;
static inline std::unordered_map m_objects;
};
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template
inline Harmony::Core::Object::Object(const uint64_t& uuid, Type* pointer) :
Harmony::Core::Object::m_uuid(Harmony::Core::Object::assignUUID(uuid))
{
Harmony::Core::Object::m_pointers[Harmony::Core::Object::m_uuid] = pointer;
}
template
inline Harmony::Core::Object::~Object()
{
assert(Harmony::Core::Object::m_pointers.contains(Harmony::Core::Object::m_uuid));
Harmony::Core::Object::m_pointers.erase(Harmony::Core::Object::m_uuid);
}
template
inline const uint64_t Harmony::Core::Object::getUUID()
{
return Harmony::Core::Object::m_uuid;
}
template
inline Type& Harmony::Core::Object::find(const uint64_t& uuid)
{
assert(Harmony::Core::Object::m_pointers.contains(uuid));
return *Harmony::Core::Object::m_pointers[uuid];
}
template
inline Type& Harmony::Core::Object::create(const uint64_t& uuid)
{
std::unique_ptr pointer = std::make_unique(uuid);
Type& reference = *pointer;
Harmony::Core::Object::add(std::move(pointer));
return reference;
}
template
inline void Harmony::Core::Object::add(std::unique_ptr pointer)
{
const uint64_t& uuid(pointer->getUUID());
assert(!Harmony::Core::Object::m_objects.contains(uuid));
Harmony::Core::Object::m_objects[uuid] = std::move(pointer);
}
template
inline void Harmony::Core::Object::rmv(const uint64_t& uuid)
{
assert(Harmony::Core::Object::m_pointers.contains(uuid));
if (Harmony::Core::Object::m_objects.contains(uuid))
Harmony::Core::Object::m_objects.erase(uuid);
if (Harmony::Core::Object::m_pointers.contains(uuid))
Harmony::Core::Object::m_pointers.erase(uuid);
}
template
inline const uint64_t Harmony::Core::Object::randomUUID()
{
static std::random_device randomDevice;
static std::mt19937_64 engine(randomDevice());
static std::uniform_int_distribution uniformDistribution;
return uniformDistribution(engine);
}
template
inline const uint64_t Harmony::Core::Object::assignUUID(const uint64_t uuid)
{
uint64_t index(uuid);
while (index == NULL or Harmony::Core::Object::m_pointers.contains(index))
index = Harmony::Core::Object::randomUUID();
return index;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79044860/static-inline-stdmap-cant-delete-class-that-contain-virtual-function-at-the-en[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия