I have this issue with this gamestate system I'm trying to implement this is the pseudo code:
Nothing new there, but then in my update function I have each state call it's update method, I am using a std::stack based gamestate system, and I am using std::unique_ptr.
The pseudo code would be like this:
std::unique_ptr<GameState> nextState = states.top()->NextState();
if(nextState != nullptr)
if(nextState->popLastState() && states.size() > 1)
then when I want to change states I just change the variable member m_State of the std::unique_ptr<GameState> object which is returned by states.top()->NextState(); to the state I want like <MenuState>
m_State = createState<MenuState>();
It works fine but then it invokes the state's constructor as it is effectively creating a new ptr each time...
so it is creating new objects that I create in the constructor EACH time I switch states, is leaking memory like crazy and that is not what I want...
When I switch to shared_ptr this does not happen, can somebody tell me why that is, or a fix to this maybe...