pure abstract class question

Why the code below kind of freeze my program?


1
2
3
GameState::GameState():pRenderer{ Game::instance().getRenderer() }
{
}


GameState is a pure abstract class and I'm initializing the pRenderer protected member of it trough Game which is a singleton.
This somehow breaks my code, ...can someone explain what is happening?
Last edited on
This somehow breaks my code, ...can someone explain what is happening?

We would have to see the relevant context to know what is happening.
actually by running the debugger and following every single step, I think I can guess what is going wrong...

Basically my Game singleton constructor looked something like this:

1
2
3
4
Game::Game() :isRunning{ true }, pWindow{ nullptr }, pRenderer{ nullptr }, currentState{nullptr}
{
     init();
}


And init() inside it had this call
 
currentState = &IntroState::instance();

so that call would trigger
1
2
3
4
GameState::GameState():pRenderer{ Game::instance().getRenderer() }
{
}
which attempted to get something out of Game singleton which didn't even finished running it's constructor... xD


So I've split the two steps like this and it now works :P
1
2
Game* GAME = &Game::instance();
GAME->init();
Last edited on
Topic archived. No new replies allowed.