C++ constructor gets xtree error

0

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

pragma once

#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?

c++
inheritance
map
asked on Stack Overflow May 22, 2014 by Canvas • edited Jun 20, 2020 by Community

1 Answer

0

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:

  1. ImageService instance don't created in Game before creating a IntroState instance
  2. Incorrect images initialization. If I know correctly in SFML sf::Texture don't inherit Sprite. This is a member of sprite.
answered on Stack Overflow Mar 12, 2020 by Evgen Buiko

User contributions licensed under CC BY-SA 3.0