Re-create MyGUI at runtime, nothing displays !!!

compvis

03-12-2009 02:47:02

hi,

I create a MyGUI system at starting up is OK but. Then at runtime, i destroy scene manager, destroy MyGUI and re-create scene manager, re-create MyGUI again, no error but MyGUI doens't display ? , all things else display normally.
I don't know why ?

my.name

03-12-2009 12:42:38

show code

compvis

04-12-2009 02:18:50

ok, this is my code:
Include file:

class GuiManager
{
public:
GuiManager();
GuiManager(K_RenderWindow _Render);
~GuiManager();
public:
K_CHECK Init();
K_EMPTY InitElements();
K_EMPTY UpdateFrameStarted(K_FLOAT elapsedTime);
K_EMPTY UpdateKeyPressed(const OIS::KeyEvent &e);
K_EMPTY UpdateKeyReleased(const OIS::KeyEvent &e);
K_EMPTY UpdateMouseMoved(const OIS::MouseEvent &e);
K_EMPTY UpdateMousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
K_EMPTY UpdateMouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);
K_EMPTY Destroy();
private:
Ogre::RenderWindow* pRender;
MyGUI::Gui pGui;
MyGUI::WindowPtr pConnectWindow;
MyGUI::StaticImagePtr pImage;
MyGUI::ProgressPtr pProgress;
MyGUI::StaticTextPtr pStatic;
MyGUI::StaticTextPtr pTargetSpeed;
};


Implement file:

#include "KLINK_GuiManager.h"

GuiManager::GuiManager():pRender(0),pGui(0),pConnectWindow(0),pImage(0),pProgress(0),pStatic(0),pTargetSpeed(0)
{

}
GuiManager::GuiManager(K_RenderWindow _Render)
{
pRender = _Render;
}
GuiManager::~GuiManager()
{
pGui = 0;
delete pGui;
}

K_CHECK GuiManager::Init()
{
pGui = new MyGUI::Gui();

if (!pGui)
{
return K_F_VALUE;
}
else
{
pGui->initialise(pRender);
}
return K_S_VALUE;
}

K_EMPTY GuiManager::InitElements()
{
MyGUI::LayoutManager::getInstance().load("Login.layout");
pStatic = MyGUI::Gui::getInstance().findWidget<MyGUI::StaticText>("Cntxt");
pStatic->setFontName("Fighter32");
pStatic->setNeedToolTip(true);
pStatic->setCaption(L"Đang kết nối...");
pProgress = MyGUI::Gui::getInstance().findWidget<MyGUI::Progress>("Progress");
pImage = MyGUI::Gui::getInstance().findWidget<MyGUI::StaticImage>("Image");
pImage->setImageTexture("Machinegun.png");
pImage->setVisible(false);
pProgress->setVisible(false);
pStatic->setVisible(false);


MyGUI::LayoutManager::getInstance().load("Distance.layout");
MyGUI::Gui::getInstance().findWidget<MyGUI::Window>("DistanceTarget")->setCaption(L"Khoảng cách");

pTargetSpeed = MyGUI::Gui::getInstance().findWidget<MyGUI::StaticText>("TSpeed");

pTargetSpeed->setFontName("Fighter48");
pTargetSpeed->setCaption(L"SIZE");
}

K_EMPTY GuiManager::UpdateFrameStarted(K_FLOAT elapsedTime)
{
if (pGui)
{
pGui->injectFrameEntered(elapsedTime);
}
}
K_EMPTY GuiManager::UpdateKeyPressed(const OIS::KeyEvent &e)
{
if (pGui)
{
pGui->injectKeyPress(e);
}
}
K_EMPTY GuiManager::UpdateKeyReleased(const OIS::KeyEvent &e)
{
if (pGui)
{
pGui->injectKeyRelease(e);
}
}

K_EMPTY GuiManager::UpdateMouseMoved(const OIS::MouseEvent &e)
{
if (pGui)
{
pGui->injectMouseMove(e);
}
}
K_EMPTY GuiManager::UpdateMousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
if (pGui)
{
pGui->injectMousePress(e,id);
}
}
K_EMPTY GuiManager::UpdateMouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
if (pGui)
{
pGui->injectMouseRelease(e,id);
}
}
K_EMPTY GuiManager::Destroy()
{
if (pGui)
{
pGui->shutdown();
delete pGui;
pGui = 0;
}
}


And in main app (starting up):


GuiManager* m_Gui;
....
m_Gui = new GuiManager(m_Render);
m_Gui->Init();
m_Gui->InitElements();
.....
Calling update functions in events: mouse, keyboard, frameStarted...


All things in good, until i destroy the scene and re-create again:

//Destroy Gui
m_Gui->Destroy();
m_Gui = 0;
delete m_Gui;
//Destroy Scene Manager
m_SceneManager->Destroy();
m_SceneManager = 0;
delete m_SceneManager;
//Re-crate scene manager
m_SceneManager = new SCeneManager(m_Root,m_Render);
m_SceneManager->Init();
//Re-create Gui
m_Gui = new GuiManager(m_Render);
m_Gui->Init();
m_Gui->InitElements();


All things display normally (Hydrax, SkyX... but except MyGUI !

compvis

06-12-2009 03:43:43

Hi,
Can anybody help ?

compvis

07-12-2009 06:03:13

@my.name, pls look my code !!!

my.name

07-12-2009 11:26:24

please wait =)

my.name

07-12-2009 11:27:10

wtf?

m_Gui = 0;
delete m_Gui;

m_SceneManager = 0;
delete m_SceneManager;

compvis

08-12-2009 01:22:02


m_Gui = 0;
delete m_Gui;

Above is to destroy MyGUI then re-create

m_SceneManager = 0;
delete m_SceneManager;

Ah,Above is to destroy scene manager and re-create, the scene manage class like below:

class ScenesManager
{
public:
ScenesManager();
ScenesManager(K_Root* _Root, K_RenderWindow _Render);
~ScenesManager();
public:
K_CHECK Init();
K_EMPTY Destroy();
K_EMPTY SetCameraLookAt(K_VECTOR _Look);
K_EMPTY SetCameraPosition(K_VECTOR _Position);
K_EMPTY SetCameraFarDistance(K_FLOAT _Distance);
K_EMPTY SetCameraNearDistance(K_FLOAT _Distance);
K_EMPTY SetCameraAspectRatio(K_FLOAT _Aspect);
K_EMPTY SetCameraFOV(K_FLOAT _Fov);
K_VECTOR GetCameraPosition();
K_FLOAT GetCameraFarDistance();
K_FLOAT GetCameraNearDistance();
K_FLOAT GetCameraAspectRatio();
K_Radian GetCameraFov();

K_SceneManager* GetScenesManager();
K_Camera GetCamera();
K_Viewport GetViewport();
public:
K_CHECK isDead;
private:
K_Root* pRoot;
K_SceneManager* pScene;
K_RenderWindow pRender;
K_Camera pCamera;
K_Viewport pViewport;
};


In fact, i have successfully re-created MyGUI at runtime (i see the MyGUI log, nothing error) but Problem is, MyGUI didn't display again. I don't know why ?

Altren

08-12-2009 13:58:42

m_Gui = 0;
delete m_Gui;

This is Not deleting m_GUI! This two lines doesn't delete anything.
delete m_Gui; - here you deleting zero pointer, not real pointer to Gui instance, so this line is exactly same as writing delete 0; that do nothing.

Also all your code have serious memory leaks because you doesn't actually delete anything and deleting zero pointers (i.e. do nothing).

You must write delete m_Gui;
m_Gui = 0;
and do same for all your destruction code. And if you don't understand why it is so - go learn C++.

qwertzui11

08-12-2009 22:33:28

nahahhaha... just lol
Support sucks ;-)

Markus

compvis

11-12-2009 05:25:23

my.name, pls help or upload a sample that re-crate mygui at runtime
thanks

my.name

11-12-2009 11:56:52

delete m_Gui;
m_Gui = 0;

delete m_SceneManager;
m_SceneManager = 0;

compvis

12-12-2009 01:44:01

delete m_Gui;
m_Gui = 0;

delete m_SceneManager;
m_SceneManager = 0;


@my.name: of course, i have implemented (then above is my ridiculous C++ problem). MyGUI didn't display again anyhow.
You can try to create a example with multi-times re-creating MyGUI system at runtime by yourselft, you will notice that MyGUI is not possible to do so

Thank you so much !

my.name

12-12-2009 09:28:53

in LayerManager

/** Set scene manager where MyGUI will be rendered */
void setSceneManager(Ogre::SceneManager * _scene);