Page 1 of 1
Problem loading Scheme File.
Posted: Thu Sep 11, 2008 10:08
by rtr_18
Hi!
I've already posted a question on Popup Menu. This is also related to that question only. The menu is loading in the GUI Window perfectly. But I want another menu to be displayed if the user presses F1 when animation is playing. GUI code and Animation code is in the same project as separate files. I've added the following code in the constructor of the Character Animation code to load the Scheme file:
Code: Select all
std::string schemeFileName = dtCore::FindFileInPathList("CEGUI/schemes/WindowsLook.scheme");
CEGUI::SchemeManager::getSingleton().loadScheme(schemeFileName);
CEGUI::System::getSingleton().setDefaultMouseCursor("WindowsLook", "MouseArrow");
CEGUI::System::getSingleton().setDefaultFont("DejaVuSans-10");
CEGUI::System::getSingleton().getDefaultFont()->setProperty("PointSize", "8");
wm = CEGUI::WindowManager::getSingletonPtr();
I've changed the visiblity of this menu when 'F1' key is Pressed. This code compiles fine. But When I run the project, it runs upto the GUI Window. When I press the start Button in the GUI to run the Character Animation, it shows already exists exception. If I trace this exception in the console window, it displays "A GUI Scheme named 'WindowsLookSkin' is already present in the System". How to load the scheme file and to display the popup in the animation Window also?
Posted: Thu Sep 11, 2008 11:53
by scriptkid
I suspect it's the same reason as the duplicate window, you might want to check whether the scheme is already loaded by calling:
Code: Select all
CEGUI::SchemeManager::getSingleton().isSchemePresent(schemeFileName);
HTH.
Posted: Fri Sep 12, 2008 06:11
by rtr_18
I've used the following code to check the presence of schemeFile and load the file. But I got the same exception.
Code: Select all
std::string schemeFileName = dtCore::FindFileInPathList("CEGUI/schemes/WindowsLook.scheme");
if(CEGUI::SchemeManager::getSingleton().isSchemePresent(schemeFileName))
{
CEGUI::SchemeManager::getSingleton().unloadScheme(schemeFileName);
}
else
{
CEGUI::SchemeManager::getSingleton().loadScheme(schemeFileName);
}
What to do to correct the exception and to display the Popup menu in the Animation Window also?
Posted: Fri Sep 12, 2008 10:55
by scriptkid
[EDIT] After typing the code below, it just hit me. IsSchemePresent accepts a *scheme* name, not a *filename*. The same counts for Fonts, Imagesets and such, in case you run into such issue again. I have changed to code below.
[/EDIT]
Maybe make it easier and just remove the call to 'unload':
Code: Select all
std::string schemeFileName = dtCore::FindFileInPathList("CEGUI/schemes/WindowsLook.scheme");
if(!CEGUI::SchemeManager::getSingleton().isSchemePresent("WindowsLookSkin"))
{ CEGUI::SchemeManager::getSingleton().loadScheme(schemeFileName);
}
else
{ // Do nothing, already loaded
}
HTH.
Posted: Mon Sep 15, 2008 11:13
by rtr_18
Here is the listing of What I've done for the Popup to be displayed in the Animation Window also:
Code: Select all
try
{
std::string schemeFileName = dtCore::FindFileInPathList("CEGUI/schemes/WindowsLookSkin");
if(!CEGUI::SchemeManager::getSingleton().isSchemePresent("WindowsLookSkin"))
{
CEGUI::SchemeManager::getSingleton().loadScheme(schemeFileName);
}
else
{
}
wm = CEGUI::WindowManager::getSingletonPtr();
CEGUI::System::getSingleton().setDefaultFont("DejaVuSans-10");
mMenuWindow = wm->createWindow("MenuSheet", "root1");
CEGUI::System::getSingleton().setGUISheet(mMenuWindow);
std::string mLayoutFilename;
if (!mLayoutFilename.empty())
{
//load GUI layout from file
CEGUI::Window *w = wm->loadWindowLayout( mLayoutFilename.c_str() );
mMenuWindow->addChildWindow(w);
}
else
{
}
CEGUI::System::getSingleton().setDefaultMouseCursor("WindowsLook", "MouseArrow");
CEGUI::System::getSingleton().setDefaultFont("DejaVuSans-10");
CEGUI::System::getSingleton().getDefaultFont()->setProperty("PointSize", "8");
wm = CEGUI::WindowManager::getSingletonPtr();
mMenuBackground = wm->createWindow("WindowsLook/StaticImage", "MenuBackgroundImage");
mMenuWindow->addChildWindow(mMenuBackground);
mMenuBackground->setPosition(CEGUI::UVector2(cegui_reldim(0.0f), cegui_reldim(0.0f)));
mMenuBackground->setSize(CEGUI::UVector2(cegui_reldim(3.0f), cegui_reldim(3.0f)));
//mMenuBackground->hide();
/*if (wm->isWindowPresent("help2"))
{ // Reuse
menu2 = static_cast<CEGUI::PopupMenu*>(wm->getWindow("help2"));
}
else
{ // Create
menu2 = static_cast<CEGUI::PopupMenu*>(wm->createWindow ("WindowsLook/PopupMenu", "help2"));
}*/
menu2 = static_cast<CEGUI::PopupMenu*>(wm->createWindow("WindowsLook/PopupMenu", "help2"));
mMenuBackground->addChildWindow(menu2);
menu2->setPosition( CEGUI::UVector2(cegui_reldim(0.36f), cegui_reldim(0.32f)));
menu2->setSize( CEGUI::UVector2(cegui_reldim(0.35f), cegui_reldim(0.43f)));
menu2->hide();
}
catch(CEGUI::Exception &e)
{
Log::GetInstance().LogMessage(Log::LOG_WARNING, __FUNCTION__,
"CEGUI::%s", e.getMessage().c_str() );
}
The above code is in the Constructor for Animation code. This is the code for 'F1' Keypress:
Code: Select all
bool TestAI::KeyPressed(const dtCore::Keyboard* keyboard, int key)
{
switch( key )
{
case osgGA::GUIEventAdapter::KEY_F1:
{
try
{
if(!menu2->isVisible())
menu2->show();
else
menu2->hide();
}
catch(CEGUI::Exception &e)
{
Log::GetInstance().LogMessage(Log::LOG_WARNING, __FUNCTION__,
"CEGUI::%s", e.getMessage().c_str() );
}
}
}
}
Still the Popup Menu is displayed in the GUI Window. But if F1 key is pressed in the Animation Window it shows exception. How to resolve? The exception is:
Unhandled exception at 0x00c1ef03 in GUI.exe: 0xC0000005: Access violation reading location 0x00000048. at the if statement inside the 'F1' case.
Posted: Mon Sep 15, 2008 12:09
by scriptkid
Are you sure that 'menu2' gets created successfully and it not destroyed before hitting F1? Have you tried setting a breakpoint in your key handler?
Posted: Mon Sep 15, 2008 12:30
by rtr_18
I set Breakpoint near this line:
Code: Select all
case osgGA::GUIEventAdapter::KEY_F1:
When I execute using F10 I can't continue beyond this line:
Exception occurs at the above line. What to do?
Posted: Mon Sep 15, 2008 18:39
by scriptkid
Okay, is "menu2" maybe a local variable in the earlier method? Since you nicely use a "m" in front of the other members.
If it is a member, do you initialize it to NULL in your constructor? Also, before hitting F10 in the offending line, does your strack trace say that menu2 is a Cegui::Window or just some bogus value?
Posted: Tue Sep 16, 2008 05:03
by rtr_18
Hi!
menu2 is a local variable only. Stack trace shows this:
CEGUI::MenuBase = {d_itemSpacing=??? d_popupItem=??? d_allowMultiplePopups=??? }
Onemore thing I forget to tell. In the Console Window, a warning is displayed:
CEGUI::WindowFactoryManager::getFactory - A WindowFactory object, an alias, or mapping for 'MenuSheet' Window Ojbects is nopt registered with the System.
Posted: Tue Sep 16, 2008 06:52
by scriptkid
Thanks for the info.
CEGUI::WindowFactoryManager::getFactory - A WindowFactory object, an alias, or mapping for 'MenuSheet' Window Ojbects is nopt registered with the System.
This is an exception actually. There is no MenuSheet window, unless you create one yourself. For the root you could use "DefaultWindow" for the type.
menu2 is a local variable only.
Well that's the answer, right? If it's local, then your 'menu2' in the handler is probably a different one? Make sure that it's the same pointer in both situations!
HTH.
Posted: Tue Sep 16, 2008 11:40
by rtr_18
Hi!
I've resolved the exceptions. But the Popup Menu is not shown up when I press 'F1' Key. There is no message in the log file also. I've posted the same code (corrected according to ur suggestions). Sorry to disturb u again and again. But I don't know what modification I've to make to display the Popup in the animation Window also.
Code: Select all
try
{
std::string schemeFileName = dtCore::FindFileInPathList("CEGUI/schemes/WindowsLookSkin");
if(!CEGUI::SchemeManager::getSingleton().isSchemePresent("WindowsLookSkin"))
{
CEGUI::SchemeManager::getSingleton().loadScheme(schemeFileName);
}
else
{
}
wm = CEGUI::WindowManager::getSingletonPtr();
CEGUI::System::getSingleton().setDefaultFont("DejaVuSans-10");
mMenuWindow = wm->createWindow("DefaultWindow", "root1");
CEGUI::System::getSingleton().setGUISheet(mMenuWindow);
std::string mLayoutFilename;
if (!mLayoutFilename.empty())
{
//load GUI layout from file
CEGUI::Window *w = wm->loadWindowLayout( mLayoutFilename.c_str() );
mMenuWindow->addChildWindow(w);
}
else
{
}
CEGUI::System::getSingleton().setDefaultMouseCursor("WindowsLook", "MouseArrow");
CEGUI::System::getSingleton().setDefaultFont("DejaVuSans-10");
CEGUI::System::getSingleton().getDefaultFont()->setProperty("PointSize", "8");
wm = CEGUI::WindowManager::getSingletonPtr();
mMenuBackground = wm->createWindow("WindowsLook/StaticImage", "BackgroundImage");
mMenuWindow->addChildWindow(mMenuBackground);
mMenuBackground->setPosition(CEGUI::UVector2(cegui_reldim(0.0f), cegui_reldim(0.0f)));
mMenuBackground->setSize(CEGUI::UVector2(cegui_reldim(3.0f), cegui_reldim(3.0f)));
mMenuBackground->hide();
/*if (wm->isWindowPresent("help2"))
{ // Reuse
menu2 = static_cast<CEGUI::PopupMenu*>(wm->getWindow("help2"));
}
else
{ // Create
menu2 = static_cast<CEGUI::PopupMenu*>(wm->createWindow ("WindowsLook/PopupMenu", "help2"));
}*/
menu2 = static_cast<CEGUI::PopupMenu*>(wm->createWindow("WindowsLook/PopupMenu", "help2"));
mMenuBackground->addChildWindow(menu2);
menu2->setPosition( CEGUI::UVector2(cegui_reldim(0.36f), cegui_reldim(0.32f)));
menu2->setSize( CEGUI::UVector2(cegui_reldim(0.35f), cegui_reldim(0.43f)));
menu2->hide();
}
catch(CEGUI::Exception &e)
{
Log::GetInstance().LogMessage(Log::LOG_WARNING, __FUNCTION__,
"CEGUI::%s", e.getMessage().c_str() );
}
The above code is in the Constructor for Animation code. This is the code for 'F1' Keypress:
Code: Select all
bool TestAI::KeyPressed(const dtCore::Keyboard* keyboard, int key)
{
switch( key )
{
case osgGA::GUIEventAdapter::KEY_F1:
{
try
{
if(!menu2->isVisible())
menu2->show();
else
menu2->hide();
}
catch(CEGUI::Exception &e)
{
Log::GetInstance().LogMessage(Log::LOG_WARNING, __FUNCTION__,
"CEGUI::%s", e.getMessage().c_str() );
}
}
}
}