You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was just working on a game where I have a call to gamestate.switch, and the leave function tries to clean up a repeating sound, but the update function starts it again. So the code execution is like this:
[states.game:update]
if weShouldSwitchStates then
State.switch(states.menu)
[states.game.leave]
sound:stop()
end
...
sound:play()
[states.menu:update]
.... (sound is playing)
You could just tell me to not do something like that, but if my update function is complex and enters a lot of other classes it's going to be hard not to have conflicts.
I'd suggest waiting until right before the new update/draw functions are called before calling leave and enter. That way I can be sure that leave is going to clean up all the resources I'm using in the gamestate.
The text was updated successfully, but these errors were encountered:
I realized that the switch function returns the results of enter on the new gamestate, so maybe that can still be called right away, with only leave being called in the next loop?
EDIT: but this results in the potential for multiple enters and inits to be called, with only one leave being called, which could also cause resource leaking.
I was just working on a game where I have a call to gamestate.switch, and the leave function tries to clean up a repeating sound, but the update function starts it again. So the code execution is like this:
You could just tell me to not do something like that, but if my update function is complex and enters a lot of other classes it's going to be hard not to have conflicts.
I'd suggest waiting until right before the new update/draw functions are called before calling
leave
andenter
. That way I can be sure that leave is going to clean up all the resources I'm using in the gamestate.The text was updated successfully, but these errors were encountered: