SceneManager->Clear() crashes!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Eldritch
Posts: 33
Joined: Mon Feb 26, 2007 12:33 pm

SceneManager->Clear() crashes!

Post 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?
c.h.r.i.s
Posts: 41
Joined: Mon Jan 22, 2007 8:38 pm

Post 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?
Strong99
Admin
Posts: 687
Joined: Fri Mar 31, 2006 7:06 pm
Location: Netherlands
Contact:

Post by Strong99 »

i quess you call removeChilds further in your code, but because scene is empty it can't and the program crashes
Eldritch
Posts: 33
Joined: Mon Feb 26, 2007 12:33 pm

Post 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.
Eldritch
Posts: 33
Joined: Mon Feb 26, 2007 12:33 pm

Post by Eldritch »

No further tips about this problem? Without a fix for it, Irrlicht is not really usable for me.
AlexL
Posts: 184
Joined: Tue Mar 02, 2004 6:06 pm
Location: Washington State

Post 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 :)
Eldritch
Posts: 33
Joined: Mon Feb 26, 2007 12:33 pm

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