charpe6
07-08-2009 19:06:37
I'm trying to destroy all the buttons created for my main menu. The problem is that no matter how I do it I always get an error when I recreate the menu that the name of the destroyed button still exists.
code:
mySheet.removeChild(myButton)
mySheet.destroyWidget(myWidget)
What am I doing wrong here?
kungfoomasta
07-08-2009 19:54:26
removing a child does not cause it to be destroyed, it basically unlinks it from the widget heirarchy. For example in Ogre you can create a SceneNode, then remove it from its parent. The SceneNode exists, however its no longer part of the scene. Likewise a detached button still exists, but is not part of the GUI. The only reason you'd want to detach widgets is to attach it to some other widget later on.
charpe6
08-08-2009 15:25:34
The reason I removeChild before I destroyWidget is because I get an error about it still having a parent
Widget it attached to another widget! in Sheet::destroyWidget
kungfoomasta
09-08-2009 06:37:18
Your code says
mySheet.removeChild(myButton)
mySheet.destroyWidget(myWidget)
Shouldn't it be
mySheet.removeChild(myButton)
mySheet.destroyWidget(myButton)
?
You could also try calling
myButton->destroy();
charpe6
12-08-2009 05:16:23
Unfortunately I'm using the quickgui version that comes with Python-Ogre and there doesn't seem to be a destroy() method for widgets.
I believe I'll just keep the button for my menus in memory since they don't take up much ram compared to the game itself and just reuse them when needed.
kungfoomasta
12-08-2009 06:26:18
Hm, I think you've uncovered a bug, and hopefully I've fixed it. When widgets are destroyed they weren't updating the Sheets name list, so when creating a new button with name X, the sheet thought a widget with name X still existed. While you're not using the latest version, I've fixed this in the latest. Thanks for bringing this up.