Używam VisualStudio z biblioteką graficzną SFML.
Mam zadeklarowaną klasę:
class Tileset
{
private:
const sf::Color MASK_COLOR = sf::Color(255, 0, 144);
sf::Texture texture;
sf::Vector2i tile_size;
int items_per_row;
int items;
std::string name;
void countItems();
public:
sf::IntRect getTile(int num);
sf::Texture& getTileset() { return texture; }
sf::Vector2i getTileSize() { return tile_size; }
Tileset(TilesetLoadData tileset_data);
Tileset();
~Tileset();
void setTexture(TilesetLoadData tileset_data);
};
Obiekt tej klasy w jednym punkcie programu tworzę dynamicznie, a w drugim chce go zwolnić:
void Textures::init()
{
buttons = new Tileset(BUTTONS);
improvements = new Tileset(IMPROVEMENTS);
fields = new Tileset(FIELDS);
units = new Tileset(UNITS);
misc = new Tileset(MISC);
checkbox = new Tileset(CHECKBOX);
}
void Textures::end()
{
delete buttons;
}
Przy usuwaniu pojawia się błąd w pliku xmemory0 w następującej funkcji:
inline
void _Deallocate(void * _Ptr, size_t _Count, size_t _Sz)
{ // deallocate storage for _Count elements of size _Sz
#if defined(_M_IX86) || defined(_M_X64)
_SCL_SECURE_ALWAYS_VALIDATE(_Count <= (size_t)(-1) / _Sz);
const size_t _User_size = _Count * _Sz;
if (_BIG_ALLOCATION_THRESHOLD <= _User_size)
{ // deallocate large block
const uintptr_t _Ptr_user = reinterpret_cast<uintptr_t>(_Ptr);
_SCL_SECURE_ALWAYS_VALIDATE( // <------------ W TEJ LINIJCE
(_Ptr_user & (_BIG_ALLOCATION_ALIGNMENT - 1)) == 0);
const uintptr_t _Ptr_ptr = _Ptr_user - sizeof(void *);
const uintptr_t _Ptr_container =
*reinterpret_cast<uintptr_t *>(_Ptr_ptr);
#ifdef _DEBUG
// If the following asserts, it likely means that we are performing
// an aligned delete on memory coming from an unaligned allocation.
_SCL_SECURE_ALWAYS_VALIDATE(
reinterpret_cast<uintptr_t *>(_Ptr_ptr)[-1] ==
_BIG_ALLOCATION_SENTINEL);
#endif /* _DEBUG */
// Extra paranoia on aligned allocation/deallocation
_SCL_SECURE_ALWAYS_VALIDATE(_Ptr_container < _Ptr_user);
#ifdef _DEBUG
_SCL_SECURE_ALWAYS_VALIDATE(2 * sizeof(void *)
<= _Ptr_user - _Ptr_container);
#else /* _DEBUG */
_SCL_SECURE_ALWAYS_VALIDATE(sizeof(void *)
<= _Ptr_user - _Ptr_container);
#endif /* _DEBUG */
_SCL_SECURE_ALWAYS_VALIDATE(_Ptr_user - _Ptr_container
<= _NON_USER_SIZE);
_Ptr = reinterpret_cast<void *>(_Ptr_container);
}
#endif /* defined(_M_IX86) || defined(_M_X64) */
::operator delete(_Ptr);
}
Zrzut ekranu z błedu:
Zrzut ze stosu wywołań:
Wskaźnik zarówno jak metody klasy Textures są statyczne więc mam pewność, że odwołują się do tego samego.
Co jest przyczyną problemu i jak go rozwiązać?