Dyn0myte
10-01-2009 02:29:04
Hi, I just recently started messing with the CEGUI. I'm trying to load in an xml layout file, however when I run the program it crashes and I get this error:
Unhandled exception at 0x766142eb in GUI_Test.exe: Microsoft C++ exception: CEGUI::InvalidRequestException at memory location 0x0012d238..
This is my code:
The file is saved in the correct directory, so I am not sure what the problem is. Any help would be much appreciated.
Unhandled exception at 0x766142eb in GUI_Test.exe: Microsoft C++ exception: CEGUI::InvalidRequestException at memory location 0x0012d238..
This is my code:
#include "ExampleApplication.h"
#include <CEGUI/CEGUI.h>
#include <OIS/OIS.h>
#include <OgreCEGUIRenderer.h>
// Both OIS & CEGUI use same key codes for keyboard input. Same is not true for mouse.
// Fucntion converts OIS button IDs into CEGUI button IDs.
CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID)
{
switch (buttonID)
{
case OIS::MB_Left:
return CEGUI::LeftButton;
case OIS::MB_Right:
return CEGUI::RightButton;
case OIS::MB_Middle:
return CEGUI::MiddleButton;
default:
return CEGUI::LeftButton;
}
}
class TutorialListener : public ExampleFrameListener, public OIS::MouseListener, public OIS::KeyListener
{
public:
TutorialListener(RenderWindow* win, Camera* cam)
: ExampleFrameListener(win, cam, true, true)
{
mContinue=true;
mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);
} // CEGUIDemoListener
bool frameStarted(const FrameEvent &evt)
{
mKeyboard->capture();
mMouse->capture();
return mContinue && !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
}
bool quit(const CEGUI::EventArgs &e)
{
mContinue = false;
return true;
}
// MouseListener
bool mouseMoved(const OIS::MouseEvent &arg)
{
// injectMouseMove function expects relative mouse movements. OIS::mouseMoved
// handler gives us those relative movements in state.X.rel & state.Y.rel variables.
CEGUI::System::getSingleton().injectMouseMove(arg.state.X.rel, arg.state.Y.rel);
return true;
}
bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
// Convert the button ID which was passed in, and pass result to CEGUI.
CEGUI::System::getSingleton().injectMouseButtonDown(convertButton(id));
return true;
}
bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
CEGUI::System::getSingleton().injectMouseButtonUp(convertButton(id));
return true;
}
// KeyListener
bool keyPressed(const OIS::KeyEvent &arg)
{
// After getting system object, we first need to inject the key down event to CEGUI.
// Then we inject the actual character that was pressed; inorder to obtain desired
// result, even with non-english keyboards.
CEGUI::System *sys = CEGUI::System::getSingletonPtr();
sys->injectKeyDown(arg.key);
sys->injectChar(arg.text);
return true;
}
bool keyReleased(const OIS::KeyEvent &arg)
{
CEGUI::System::getSingleton().injectKeyUp(arg.key);
return true;
}
private:
bool mContinue;
};
class CEGUIDemoApplication : public ExampleApplication
{
public:
CEGUIDemoApplication()
: mSystem(0), mRenderer(0)
{
}
~CEGUIDemoApplication()
{
if (mSystem)
delete mSystem;
if (mRenderer)
delete mRenderer;
}
protected:
CEGUI::System *mSystem;
CEGUI::OgreCEGUIRenderer *mRenderer;
void createScene(void)
{
// Initialize the CEGUI.
using namespace CEGUI;
mRenderer = new OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
mSystem = new System(mRenderer);
Window* myRoot = WindowManager::getSingleton().loadWindowLayout( "test.layout" );
System::getSingleton().setGUISheet( myRoot );
}
void createFrameListener(void)
{
mFrameListener= new TutorialListener(mWindow, mCamera);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}
};
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
// Create application object
CEGUIDemoApplication app;
try {
app.go();
} catch(Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!",
MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\n",
e.getFullDescription().c_str());
#endif
}
return 0;
}
The file is saved in the correct directory, so I am not sure what the problem is. Any help would be much appreciated.