Okay let's give it a shot.
I don't think there's any sense in posting all classes' code so let's focus on StateMenu.
What's more, I found strange thing when playing with the code, but let's post it firstly:
main.cpp#include "Window.h"
//...
void changeState(IState *(&state))
{
if ( state->getStateMenu() )
{
delete state;
state = new StateMenu();
}
else if ( state->getStateOptions() )
{
delete state;
state = new StateOptions();
}
else if ( state->getStateManage() )
{
delete state;
state = new StateManage();
}
else if ( state->getStateStart() )
{
delete state;
state = new StateStart();
}
}
int main()
{
Sound::instance().playSoundtrack();
IState* state = new StateMenu();
while(!state->toExit())
{
state->update();
state->render();
changeState(state);
}
delete state;
return 0;
}
IState.h#pragma once
#include "Flashcards.h"
#include "Window.h"
#include "Button.h"
#include "Sound.h"
#include <SFML/Graphics.hpp>
class IState
{
protected:
//...
sf::Texture t_background;
sf::Sprite background;
public:
IState();
virtual ~IState() {};
virtual void update() = 0;
virtual void render() = 0;
//...
};
StateMenu.hclass StateMenu : public IState
{
private:
const short TOTAL_BUTTONS;
sf::Vector2f buttonSize;
Button start;
Button manage;
Button options;
Button exit;
Button speaker;
sf::Text text;
sf::String string;
public:
StateMenu();
~StateMenu() {};
//...
};
So, the anomaly I found is when I comment all buttons from StateMenu.h (class Button contains Caption object, and Caption class contains sf::Text and sf::Font), declare sf::Text variable into StateMenu.h and comment following two lines from IState.h class:
sf::Texture t_background;
sf::Sprite background;
... there is no crash. However, if I decalre buttons and comment background lines from IState, the crash still happens. What the hell? How is this even connected? Maybe there's something wrong with IDE I use? I'm super confused right now.