I'm trying to construct one of my classes but i'm getting a xtree violation error. Here is how I am constructing my classes
Game.h
#pragma once
#include "ImageService.h"
class Game
{
private:
IntroState introState;
public:
ImageService imageService;
Game();
~Game();
};
game.cpp
Game::Game() : introState(imageService)
{
}
This then goes to introState
IntroState.h
#include "State.h"
class IntroState : public State
{
public:
IntroState(ImageService &imageService);
~IntroState();
GameState objectState;
};
IntroState.cpp
#include "IntroState.h"
IntroState::IntroState(ImageService& imageService) : State (imageService)
{
}
IntroState::~IntroState()
{
}
This then goes to State
State.h
#pragma once
#include "ImageService.h"
class State
{
private:
ImageService imageService;
public:
State( ImageService& is );
~State();
};
State.cpp
#include "State.h"
State::State(ImageService& _imageService)
{
imageService = _imageService;
}
State::~State()
{
}
This then goes to the constructor of the image service
ImageService.h
#pragma once
#include <map>
#include "Enums.h"
#include "Sprite.h"
class ImageService
{
public:
ImageService();
~ImageService();
std::map<ImageName, Sprite> Images;
};
ImageService.cpp
ImageService::ImageService()
{
Images = std::map<Image, sf::Texture>();
}
ImageService::~ImageService()
{
}
Now here are the steps it goes thought and crashes
1 : Game constructor
2 : IntroState constructor
3 : State constructor
4 : ImageService constructor
5 : Images are then set to an empty map
6 : Trying to assign ImageService reference to State
7 : Xtree error shown (Unhandled exception at 0x012BF147 in Dungeon_Wraight.exe: 0xC0000005: Access violation reading location 0x00000004.)
This is the function in xtree
template<class _Moveit>
void _Copy(const _Myt& _Right,
_Moveit _Movefl)
{ // copy or move entire tree from _Right
_Root() = _Copy_nodes(_Right._Root(), this->_Myhead, _Movefl); //Here is the error
this->_Mysize = _Right.size();
if (!this->_Isnil(_Root()))
{ // nonempty tree, look for new smallest and largest
_Lmost() = this->_Min(_Root());
_Rmost() = this->_Max(_Root());
}
else
{ // empty tree, just tidy head pointers
_Lmost() = this->_Myhead;
_Rmost() = this->_Myhead;
}
}
Why on earth am I getting this error?
Xtree implement some memory and time features of std::set
and std::map
. Knowing this, error can be appeared in 2 places of your code:
ImageService
instance don't created in Game
before creating a IntroState
instanceimages
initialization. If I know correctly in SFML sf::Texture
don't inherit Sprite
. This is a member of sprite.User contributions licensed under CC BY-SA 3.0