Page 1 of 1

SceneManager->Clear() crashes!

Posted: Sat Mar 17, 2007 10:59 am
by Eldritch
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?

Posted: Sat Mar 17, 2007 12:44 pm
by c.h.r.i.s
Hi! I can not understant your question. Why you want to hide all objects? Yust lay the menu over the scene. Or yust deactivate the camera node. I think your problem is that you have maybe still any pointers, that are pointing to scenenodes that will be erased, if you call clear();

Code?

Posted: Sat Mar 17, 2007 1:25 pm
by Strong99
i quess you call removeChilds further in your code, but because scene is empty it can't and the program crashes

Posted: Sat Mar 17, 2007 2:14 pm
by Eldritch
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.

Posted: Wed Mar 21, 2007 8:03 am
by Eldritch
No further tips about this problem? Without a fix for it, Irrlicht is not really usable for me.

Posted: Wed Mar 21, 2007 8:24 am
by AlexL
Eldritch,
You must be trying to access a released node or something to the like. As in my project, I am using the clear method quiet often without a crash, error, warning or otherwise. It would help if you could post some code showing what you are doing exactly :)

Posted: Wed Mar 21, 2007 12:00 pm
by Eldritch
I dont have the code with me right now, but I can show you the pseudo:

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
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.