I have multiple game states in my engine based on Irrlicht, and when I switch between different game states I make sure to clear the SceneManager so there are no redundant objects from previous states laying around.
I have two states at the moment: menu and game. If I switch between them continously, the game will crash at RemoveChild() (I guess this is called from Clear()) saying I am attempting to read/write protected memory.
What can be wrong?
Is there a better way to "hide" all objects from another state?
SceneManager->Clear() crashes!
i quess you call removeChilds further in your code, but because scene is empty it can't and the program crashes
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
The reason why I want to hide my objects is many fold. Say I complete a level and want to load another one.. I need to clear the scene of all previous objects so they don't appear in the new level. That is one example. Another example is if I go from Main Menu to Game and then back to Main Menu. Then I'd also need to clear the scene of all objects.
I am only doing Clear(), I never do any removal of child nodes anywhere else. The Clear() is done when I switch states, but it does not crash on the first few swaps between states, only after 3+ swaps (Menu->Game->Menu->Game->Menu *crash*, for example).
On a side note.. I am using Irrlicht.NET CP and C#, but that should not be any different unless the guy(s) who made it have seriously missed something.
I am only doing Clear(), I never do any removal of child nodes anywhere else. The Clear() is done when I switch states, but it does not crash on the first few swaps between states, only after 3+ swaps (Menu->Game->Menu->Game->Menu *crash*, for example).
On a side note.. I am using Irrlicht.NET CP and C#, but that should not be any different unless the guy(s) who made it have seriously missed something.
I dont have the code with me right now, but I can show you the pseudo:
Now, you are probably thinking why I clear the graph twice. I do because if I switch from a game mode back to a menu mode, I need to clear both states to avoid having redundant things in the Object Lib and GUI Lib.
You might also be thinking you see the cause of the crash when I clear the scene graph twice, but here is the funny thing. The first two times I do this switch between states, no crash occurs. It only occurs after the first two times.
Code: Select all
public void SetState(State newState)
if (this.currState != null)
this.currState.Clear() // clears the scene graph, obj lib and gui lib
this.currState = newState
newState.Clear() // clears the scene graph, obj lib and gui lib
Code: Select all
public void Clear()
this.ObjLib.Clear()
this.GUILib.Clear()
SceneLib.Instance.Clear() // SceneLib = reference to SceneManager
You might also be thinking you see the cause of the crash when I clear the scene graph twice, but here is the funny thing. The first two times I do this switch between states, no crash occurs. It only occurs after the first two times.