Problem creating a simple window in Ogre

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

majc
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Sat Apr 12, 2008 20:55

Problem creating a simple window in Ogre

Postby majc » Wed Aug 13, 2008 20:01

Im trying to create a simple window when i click in an npc but for some reason give me a memory error.

Here is the code:

Code: Select all

void cGUIInterface::vendorMenu()
{
   CEGUI::SchemeManager::getSingleton().unloadAllSchemes();
   loadScheme("TaharezLookSkin.scheme");
   mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
   CEGUI::FontManager::getSingleton().createFont("Commonwealth-10.font");
   CEGUI::WidgetLookManager::getSingleton().parseLookNFeelSpecification("TaharezLook.looknfeel");
   CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
   CEGUI::DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
   CEGUI::System::getSingleton().setGUISheet(root);
   FrameWindow* wnd = (FrameWindow*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/FrameWindow", (CEGUI::utf8*)"Window");
   root->addChildWindow(wnd);
   wnd->setPosition(CEGUI::UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
   wnd->setSize(CEGUI::UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
   wnd->setMaxSize(CEGUI::UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
   wnd->setMinSize(CEGUI::UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
   wnd->setText("Weapons Vendor");
}


Give the error in this line:

Code: Select all

FrameWindow* wnd = (FrameWindow*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/FrameWindow", (CEGUI::utf8*)"Window");


Thanks in advance!

Bane
Just popping in
Just popping in
Posts: 4
Joined: Tue Aug 12, 2008 21:54

Postby Bane » Wed Aug 13, 2008 20:40

have you tried just a regular window?

majc
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Sat Apr 12, 2008 20:55

Postby majc » Wed Aug 13, 2008 21:42

How i do that?

majc
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Sat Apr 12, 2008 20:55

Postby majc » Wed Aug 13, 2008 21:43

How i do that? Can you give me an example?

Bane
Just popping in
Just popping in
Posts: 4
Joined: Tue Aug 12, 2008 21:54

Postby Bane » Wed Aug 13, 2008 22:09

sure look at my post about generalized windows in the forum, right under yours right now.

or basically change CEGUI::FrameWindow*
to just CEGUI::Window*

majc
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Sat Apr 12, 2008 20:55

Postby majc » Wed Aug 13, 2008 22:38

Yes :(

User avatar
Kevin
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon May 26, 2008 15:44

Postby Kevin » Thu Aug 14, 2008 01:09

The specific error should be listed at (or towards) the bottom of CEGUI.log after running the program. I can't be sure, but it seems like the error is likely a result of there being another window registered with the system named "Window". All windows in the entire CEGUI system must have unique names. So you could either try naming it something else, or (as of a fairly recent release of CEGUI), you can try omitting that parameter, and then the system will generate a unique name for you. The only problem with the latter option is you can then no longer refer to that window by name in other parts of the code.

If this is the not the problem (or that doesn't help) I would still recommend seeing what's in CEGUI.log.

Hope that helps.
Kevin

majc
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Sat Apr 12, 2008 20:55

Postby majc » Fri Aug 15, 2008 09:00

Yes Kevin was that the problem thanks alot mate :)
But now i have another problem :S in the tutorials and exemples i only found code that we can interact with buttons loading an existing overlay, if i want to add a quit default button i must load an overlay file or i can create a new button like i did with the FrameWindow?
Here is the code i have until now:

Constructor:

Code: Select all

cGUIInterface::cGUIInterface(cGraphicalInterface *graphicalInterface)
{
   // setup GUI system
   mGraphInterface = graphicalInterface;
   mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mGraphInterface->getWindow() , Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mGraphInterface->getSceneManager());
   mGUISystem = new CEGUI::System(mGUIRenderer);
   CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
   winMgr = &CEGUI::WindowManager::getSingleton();
   root = (DefaultWindow*)winMgr->createWindow("DefaultWindow", "Root");
   CEGUI::System::getSingleton().setGUISheet(root);
   vendorWindow = 0;
}


Other functions needed for this example:

Code: Select all

CEGUI::MouseButton cGUIInterface::convertOISMouseButtonToCegui(int buttonID)
{
    switch (buttonID)
    {
   case 0: return CEGUI::LeftButton;
   case 1: return CEGUI::RightButton;
   case 2:   return CEGUI::MiddleButton;
   case 3: return CEGUI::X1Button;
   default: return CEGUI::LeftButton;
    }
}


Code: Select all

bool cGUIInterface::handleQuit(const CEGUI::EventArgs& e)
{
   if (vendorWindow)
      CEGUI::WindowManager::getSingleton().destroyWindow(vendorWindow);
   return true;
}


Vendor Menu window where i want to put the button to buy or sell:

Code: Select all

void cGUIInterface::vendorMenu()
{
   
   //CEGUI::SchemeManager::getSingleton().unloadAllSchemes();
   //loadScheme("TaharezLookSkin.scheme");
   //CEGUI::FontManager::getSingleton().createFont("Commonwealth-10.font");
   //CEGUI::WidgetLookManager::getSingleton().parseLookNFeelSpecification("TaharezLook.looknfeel");
   if (vendorWindow)
      CEGUI::WindowManager::getSingleton().destroyWindow(vendorWindow);
   vendorWindow = (FrameWindow*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"TaharezLook/FrameWindow", (CEGUI::utf8*)"Window");
   root->addChildWindow(vendorWindow);
   mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
   vendorWindow->setPosition(CEGUI::UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
   vendorWindow->setSize(CEGUI::UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
   vendorWindow->setMaxSize(CEGUI::UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
   vendorWindow->setMinSize(CEGUI::UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
   vendorWindow->setText("Weapons Vendor");
   CEGUI::PushButton* pQuitButton = (CEGUI::PushButton *)CEGUI::WindowManager::getSingleton().getWindow("DefaultWindow");
   pQuitButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&cGUIInterface::handleQuit, this));
   //winMgr->getWindow((CEGUI::utf8*)"TaharezLook/Button")->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&cGUIInterface::handleQuit, this));
}


Here is the log error:

Code: Select all

14/08/2008 01:36:28 (Error)   CEGUI::UnknownObjectException in file \Projects\CEGUI\cegui_mk2-v0-6-2003\src\CEGUIWindowManager.cpp(180) : WindowManager::getWindow - A Window object with the name 'DefaultWindow' does not exist within the system


But the default window is beeing created in the contructor :S
or all this things it seems to be easier to load Windows and buttons from a overlay file created previously.
What you advice? What is the best way? Create de windows and buttons or load them from a overlay?
Thanks in advance!

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Postby Jamarr » Fri Aug 15, 2008 16:11

I think you are getting your WindowType and WindowName mixed up.

When you create a type of "DefaultWindow" in the constructor, you are giving it the name "Root". So if you are trying to access that window, you need to use WindowManager::getWindow("Root") instead; optionally, since that is also your GUISheet, you could use System::getGUISheet().

majc
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Sat Apr 12, 2008 20:55

Postby majc » Fri Aug 15, 2008 16:50

Thanks mate :)


Return to “Help”

Who is online

Users browsing this forum: No registered users and 11 guests