Page 1 of 1

closing, hiding or destroying a window , HELP!

Posted: Mon Nov 07, 2005 02:34
by wuack
Please help!
I am not only new to CEGUI, but also a clumsy programmer.

I am working on GUI for a simulation program, in which i need to make windows that pop up and close on command.

I create pop up window lay out in xml sheet, and call loadWindowLayout when a button is clicked to display these windows. That works just fine.

The problems come when i try to make these windows disappear (after finish using them):

I have tried to hide them:

bool handleCancel(const CEGUI::EventArgs& e)
{
CEGUI::Window* mEditorGuiSheet = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"Load");
mEditorGuiSheet->hide();
return true;
}

I have tried to destroy them:

bool handleCancel(const CEGUI::EventArgs& e)
{
CEGUI::Window* mEditorGuiSheet = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"Load");
CEGUI::WindowManager::getSingleton().destroyWindow(mEditorGuiSheet);
return true;
}

and these 2 methods both help my program to CRASH.

I've read some where that destroying a window that fires event may make my program crash. What should i do to avoid it? Why doesn't the hide method work?

i have looked around for a while and still can't figure out how to close any of the window i create. I appreciate everymuch your help. please leave let me know if you need more information about the problems.

Thanks

Re: closing, hiding or destroying a window , HELP!

Posted: Mon Nov 07, 2005 08:06
by Rellik
is the crash happening after u hide the window or after u try to re-open it?

Re: closing, hiding or destroying a window , HELP!

Posted: Mon Nov 07, 2005 21:59
by wuack
the program would run fine without the code to hide or destroy the windows.

but if i put code to hide and destroy the windows in, the program crashes right after it starts. i dont even get to see my screen. a window just pops up saying "the application has requested the Runtime to termintate it in an unsual way. Please contact the application's support team for more information."

Re: closing, hiding or destroying a window , HELP!

Posted: Mon Nov 07, 2005 22:38
by lindquist
which CEGIU version?

How do you subscribe to your events?

Any logger errors?

Re: closing, hiding or destroying a window , HELP!

Posted: Tue Nov 08, 2005 00:48
by wuack
i think it is one versio older than the newest one, but i'm not sure. i dotn know how to figure it out. i just use this version since it comes with ogre3d v1.0.

here's the code i use to subcribe the events
void setupEventHandlers(void)
{
CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
wmgr.getWindow((CEGUI::utf8*)"OgreGuiDemo/Quit")
->subscribeEvent(
CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&GuiApplication::handleQuit, this));

wmgr.getWindow((CEGUI::utf8*)"OgreGuiDemo2/ControlWindow/ShowCodeBtn")
->subscribeEvent(
CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&GuiApplication::handleShowCode, this));

wmgr.getWindow((CEGUI::utf8*)"OgreGuiDemo/FileMenu")
->subscribeEvent(
CEGUI::Combobox::EventListSelectionAccepted,
CEGUI::Event::Subscriber(&GuiApplication::handleObjectSelection, this));

wmgr.getWindow((CEGUI::utf8*)"Load/MainWindow/LoadCancel")
->subscribeEvent(
CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&GuiApplication::handleCancel, this));
}



if i take that last one subscribeEvent out, the program would run, but if it's in there the program would crash.

there's what's inside of the handleCancel
bool handleCancel(const CEGUI::EventArgs& e)
{
CEGUI::Window* mEditorGuiSheet = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"Load/MainWindow");
mEditorGuiSheet->hide();

return true;
}

or

bool handleCancel(const CEGUI::EventArgs& e)
{
CEGUI::Window* mEditorGuiSheet = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"Load/MainWindow");
CEGUI::WindowManager::getSingleton().destroyWindow(mEditorGuiSheet);

return true;


i have tried both hiding and destroying the window, neither of them work.

What is "logger error"? how do i find that out?

Appreciate the help very much

Re: closing, hiding or destroying a window , HELP!

Posted: Tue Nov 08, 2005 04:25
by Gaal
It seems that there is inconsistency between the declaration of you window in the layout file and the event subscribe declaration.
Please verify the name of the window.
is it "Load/MainWindow/LoadCancel" or "Load/MainWindow" or anything else ?

You have to match the window name!


The "Error Log" is that file called Cegui.log in the execution directory.
You can find the CeGUI version number in. And other error message.
Each time you have an error and want some help, please copy the exact error message.

Gaal

Re: closing, hiding or destroying a window , HELP!

Posted: Tue Nov 08, 2005 05:56
by wuack
Gaal wrote:
It seems that there is inconsistency between the declaration of you window in the layout file and the event subscribe declaration.
Please verify the name of the window.
is it "Load/MainWindow/LoadCancel" or "Load/MainWindow" or anything else ?

You have to match the window name!


the windows' names dont match because they're for different window componentz. Load/MainWindow/LoadCancel is a button that i'd like to click on to fire closing event for Load/MainWindow, which is a window. it just happen that the LoadCancel button is on the MainWindow.

it's sort of like when you open a window to do something, then decide not todo it, so you click cancel, to close that window away.

The "Error Log" is that file called Cegui.log in the execution directory.
You can find the CeGUI version number in. And other error message.
Each time you have an error and want some help, please copy the exact error message.


yeah the log file helps me to understand some stuff better. it doesn't work yet, i'm learning about event subscribing still.

i'll post again, when i get to the point to ask questions again. thanks for your help

Re: closing, hiding or destroying a window , HELP!

Posted: Tue Nov 08, 2005 07:14
by wuack
things work now, thank you for your help.

however, i do have another problem related to closing a window. i was instructed to do this in order to subscribe an event fired by the closeButton on a frame window:

void setupCloseButtonHandlers(CEGUI::Window* window)
{
window->subscribeEvent(
CEGUI::FrameWindow::EventCloseClicked,
CEGUI::Event::Subscriber(&GuiApplication::handleCloseButton, this));
}


but when i compile this, i have these errors:

error C2027: use of undefined type 'FrameWindow'
c:\ogresdk\include\cegui\ceguiforwardrefs.h(80) : see declaration of 'FrameWindow'
error C2065: 'EventCloseClicked' : undeclared identifier


i have checked 2 million times to make sure FrameWindow was not misspelled. how else can it be undefined?

Re: closing, hiding or destroying a window , HELP!

Posted: Tue Nov 08, 2005 09:05
by scriptkid
i have checked 2 million times to make sure FrameWindow was not misspelled. how else can it be undefined?


A type is never just "FrameWindow" or "Button". There's always a looknfeel prefix, so it becomes "WindowsLook/FrameWindow" for example.

[EDIT] i see it a compile error now; did you use the CEGUI namespace or prefix FrameWindow with it?
[/EDIT]

As a hint for your original post: Always test returned pointers (in this case windows) for not being NULL, before calling methods on it!

Good luck :-)

Re: closing, hiding or destroying a window , HELP!

Posted: Tue Nov 08, 2005 16:29
by lindquist
include "CEGUI.h" or at least "elements/CEGUIFrameWindow.h"

Re: closing, hiding or destroying a window , HELP!

Posted: Thu Nov 10, 2005 06:03
by wuack
Thank you, i did include the header file in and it works now. But geesh, the problems dont come individually, they come in herds :D

therefore, i have other problems that i need help with. i scoured the site and couldn't find anything that would answer this.

so i ran my Gui app, i opened a window within it. then, i closed it. AND I WANT TO OPEN IT BACK UP AGAIN, but the program CRASHESwhen i try to click o button to open in back up.

here's how the code look:
void setupEventHandlers(void)
{

CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();


wmgr.getWindow((CEGUI::utf8*)"OgreGuiDemo/FileMenu")
->subscribeEvent(
CEGUI::Combobox::EventListSelectionAccepted,
CEGUI::Event::Subscriber(&GuiApplication::handleObjectSelection, this));
}


bool handleObjectSelection(const CEGUI::EventArgs& e)
{
static unsigned int load = 0;
static unsigned int save = 1;
String guiObjectName;
CEGUI::Window* window = 0;

// Set a position to place this object.
Real posX = 0.5;
Real posY = 0.5 ;

const CEGUI::WindowEventArgs& windowEventArgs = static_cast<const CEGUI::WindowEventArgs&>(e);
CEGUI::ListboxItem* item = static_cast<CEGUI::Combobox*>(windowEventArgs.window)->getSelectedItem();

CEGUI::Window* editorWindow = CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"OgreGuiDemo2");

switch(item->getID())
{
case 0:

if(mEditorGuiSheet)
mEditorGuiSheet->destroy();


mEditorGuiSheet = CEGUI::WindowManager::getSingleton().loadWindowLayout(
(CEGUI::utf8*)"LoadWin.layout");
setupLoadWindowHandlers();
break;

};

editorWindow->addChildWindow(mEditorGuiSheet);

return true;
}



void setupLoadWindowHandlers(void)
{
CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();

mCancelBtn =
wmgr.getWindow((CEGUI::utf8*)"Load/MainWindow/LoadCancel");
mCancelBtn->subscribeEvent(
CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&GuiApplication::handleCancel, this));
}

bool handleCloseButton(const CEGUI::EventArgs& e)
{
static_cast<const CEGUI::WindowEventArgs&>(e).window->hide();
return true;
}


i dont quite understand how these windows and sheets get attached and detached.

in short, the whole problem is i need to be able to open a window within the program, use it, be able to close it, and reopen it if i need to. i would be very thankful, if you guys an educate me a bit about these things, or at least show me where to go in the site that i can learn more about this. i did most of this, just looking demo code. i understand some, but not all that i did there.

thank you

Re: closing, hiding or destroying a window , HELP!

Posted: Thu Nov 10, 2005 12:31
by martignasse
from the code you posted, i can't say what is wrong.

But basicly, if you have a window you want to use many time in the appli, you don't have to destroy it and reload it every time, just hide() and show() it.

Re: closing, hiding or destroying a window , HELP!

Posted: Thu Nov 10, 2005 20:23
by wuack
i have tried hiding. it causes the same problem.

this is how is hide a window. i copied it from somewhere, so i dont really understand what it's doing there, besides that '->hide()'. How does it know what to hide? What do all that in front of "->hide()" mean? ... since i dont understand completely, i'm not sure how to show a window correct after hiding it.

here's how that code for hiding looks:

bool handleCloseButton(const CEGUI::EventArgs& e)
{
static_cast<const CEGUI::WindowEventArgs&>(e).window->hide();
return true;
}

Re: closing, hiding or destroying a window , HELP!

Posted: Thu Nov 10, 2005 22:01
by martignasse
i have tried hiding. it causes the same problem.
it wasn't to resolve the error but more in an "educate" way ;-)

problem with lot of copy/past from lot of different sources is that you finish with lot of bug.

What do all that in front of "->hide()" mean?

if you don't understand it....don't copy/past it :x
"static_cast<const CEGUI::WindowEventArgs&>(e).window" extract a pointer to the window who fire the event.

i suggest you to make some minimal projects with only CEGUI (not with orge, based on the SampleApp) and only the fonctionnality you want to test/anderstand.
Like that, you only have the code relevant to the fonctionnality, it's easy to understand and to debug.

and look in the cegui.log (located in the exe folder), it can help(sometime) to locate the error.