Problem use MyGUI in AdvancedOgreFramework

randomcode

31-01-2017 03:58:48

Hello, I meet some trouble when i try to use MyGui in AdvancedOgreFramework

There are Three States in AdvancedOgreFramework: MenuState(Main Menu), NewGameState( Main Single Player Game ), PauseState( will display when pause )

I create a GUI in MenuState, here is the code:

OgreFramework::getSingletonPtr()->m_Platform=new MyGUI::OgrePlatform();
OgreFramework::getSingletonPtr()->m_Platform->initialise(OgreFramework::getSingletonPtr()->m_pRenderWnd,m_pSceneMgr,"General");
OgreFramework::getSingletonPtr()->m_Gui=new MyGUI::Gui();
OgreFramework::getSingletonPtr()->m_Gui->initialise();


I destroy m_Platform and m_Gui in the exit() function in MenuState:

OgreFramework::getSingletonPtr()->m_Gui->destroyAllChildWidget();

//OgreFramework::getSingletonPtr()->m_Gui->shutdown();
delete OgreFramework::getSingletonPtr()->m_Gui;
OgreFramework::getSingletonPtr()->m_Gui=0;
delete OgreFramework::getSingletonPtr()->m_Platform;
OgreFramework::getSingletonPtr()->m_Platform=0;


I want to create another GUI in my NewGameState(I need to recreate m_Gui and m_Platform because i want to bind NewGameState scene manager to MyGUI)

OgreFramework::getSingletonPtr()->m_Platform=new MyGUI::OgrePlatform();
OgreFramework::getSingletonPtr()->m_Platform->initialise(OgreFramework::getSingletonPtr()->m_pRenderWnd,m_pSceneMgr,"General");
OgreFramework::getSingletonPtr()->m_Gui=new MyGUI::Gui();
OgreFramework::getSingletonPtr()->m_Gui->initialise();


Here is my problem:

When I try to enter my NewGameState, the application notice error and exit, when i checked the MyGUI.log, it says:

11:44:27 | Platform | Info | * Initialise: RenderManager | C:\Repository\MyGUI\MyGUI_3.2.0\Platforms\Ogre\OgrePlatform\src\MyGUI_OgreRenderManager.cpp | 43
11:44:27 | Platform | Info | RenderManager successfully initialized | C:\Repository\MyGUI\MyGUI_3.2.0\Platforms\Ogre\OgrePlatform\src\MyGUI_OgreRenderManager.cpp | 71
11:44:27 | Platform | Info | * Initialise: DataManager | C:\Repository\MyGUI\MyGUI_3.2.0\Platforms\Ogre\OgrePlatform\src\MyGUI_OgreDataManager.cpp | 27
11:44:27 | Platform | Info | DataManager successfully initialized | C:\Repository\MyGUI\MyGUI_3.2.0\Platforms\Ogre\OgrePlatform\src\MyGUI_OgreDataManager.cpp | 35
11:44:27 | Core | Info | * Initialise: Gui | C:\Repository\MyGUI\MyGUI_3.2.0\MyGUIEngine\src\MyGUI_Gui.cpp | 75
11:44:27 | Core | Info | * MyGUI version 3.2.0 | C:\Repository\MyGUI\MyGUI_3.2.0\MyGUIEngine\src\MyGUI_Gui.cpp | 87
11:44:27 | Core | Critical | Singleton instance ResourceManager already exsist | c:\repository\mygui\mygui_3.2.0\myguiengine\include\MyGUI_Singleton.h | 43


It seems like that i need to destroy the ResourceManager Instance
So how did I destroy the resourcemanager instance so that i can create the GUI in different state? Thank you

Altren

03-02-2017 20:17:18

First of all, are you sure that you need to recreate whole Gui when changing state? It seems wrong because MyGUI parse all it's XML resources on initialization and I see no point of doing this when switching between states. You should destroy all widgets if you want to, but it is pointless to destroy Gui.

What about your code - it looks correct and MyGUI Manager classes are created and destroyed in MyGUI::Gui and MyGUI::OgrePlatform. You never need to manually destroy or create anything else. Make sure, that you are accessing Gui from the same thread if you have multithreaded application.