In my game, I have a main menu that launches different levels based on what the player clicks. The game loads successfully, but when I try to remove the game and exit to the menu and reload the game, it results in a glitchy game screen and the RAM usage goes up. Is this how I’m supposed to use appstates? Am I cleaning up the resources properly? Also, is there a way to delete the scene model like in OpenGL? Any help is appreciated. Also, by “glitchy” I mean the game loads and everything works properly, but the objects are all transparent and the game is slow. Maybe it has something to do with a shadow renderer I attached to the viewport?
Just to debug the issue, I deleted the scene mesh in the cleanup method. Like I expected, it threw a fatal error. Maybe I’m not removing the scene properly? I’ll follow up with some of my findings from the error log, but here is my new code to clean up the appstate:
“sound” is not an AppState. I changed the bullet cleanup code to just stateManager.detach(bullet) but
the error seems to occur with the mesh because the java vm error says
You are only showing little snippets of code… but it is enough to know that maybe you don’t know how app states are supposed to work.
Extend BaseAppState
Do everything you create in the initialize() or onEnable() depending on how ‘resident’ they should be.
Clean up everything you create in the cleanup() or onDisable() depending on where you created them.
attach app states when you want to use them, disable them when you want to not use them… very rarely, detach them when you will never ever use them again.
Ok, I think I just need to manually remove the shadow renderer and the other post processing filters. This solved the rendering issues. The RAM issues still persist, though, but I don’t think they’ll matter for my game. Also, input.clearMappings() seems to get rid of the mouse mappings. Is there a way to add them back?
Thanks.
at the end of the cleanup method but I get this error:
java.lang.RuntimeException: No OpenGL context found in the current thread.
i think the problem has to do with the FilterPostProcessor.
As a side note, the colors seem to change slightly (not gamma (not/double gamma corrected?) when running the game appstate the second time.
I just added multiple ambient lights because I forgot to remove the old one.
Thank you so much pspeed!
Your advice of adding the post processing filters and shadow renderer once worked! I guess the post processing filters just don’t like to be added and removed from the jme renderer!
Probably OT, but this is what I do:
render a full screen quad with “loading…” on it
add a 1-pixel scene that includes every possible texture
detach both of these after the first update loop
Yes. The problem, however, was actually that the asset manager was returning a cached object after it had been manually deleted. I am currently making the bullet app state static and constant throughout the game.
I don’t think you have much of clue about what you’re doing, and while I encourage working things out, I strongly recommend you leave that static keyword alone, along with trying to “fix” the engine because there’s nothing wrong with it. Please spend your time learning, and not waving that massive stabby knife around butchering everything in your path.
After having a quick read of the thread, I think your problem is not the Appstate management.
Appstates are intended to help keep things tidy, but they aren’t a magical silver bullet if you don’t clean stuff properly. As @jayfella said, have a second look at the tutorials.