Page 1 of 1

An overlay troubles.

Posted: Sat Feb 05, 2005 3:36 pm
by ZeroMem
Hello, there. I've been using OGRE engine for a cope of month. And I have a big problem with overlay.
I’ve been using overlay for showing FPS info. For this stuff I have created one class derived from FrameListener. Here’s the code:

Code: Select all

Ogre::RenderWindow* _pWnd;
Ogre::Font* _pFont;
Ogre::TextAreaGuiElement* guiDebug;
const Ogre::RenderTarget::FrameStats* stats;
Ogre::Overlay* o;
Ogre::PanelGuiElement* panGui;


	CGameDebugFrameListener::CGameDebugFrameListener(Ogre::RenderWindow* pWindow, 
													Ogre::Real detail,
													const std::string& fontname)
	{
		this->panGui = NULL;
		
		_pWnd = pWindow;
		this->_pFont = static_cast<Ogre::Font*>(Ogre::FontManager::getSingletonPtr()->getByName("Times_New_Roman"));
		this->_pFont->setSource(fontname);
		this->_pFont->setTrueTypeSize(32);
		this->_pFont->setTrueTypeResolution(55);
		this->_pFont->setType(Ogre::FT_TRUETYPE);
		try{
			this->_pFont->load();
		}catch(...){}
		guiDebug = static_cast<Ogre::TextAreaGuiElement*>(Ogre::GuiManager::getSingletonPtr()->createGuiElement("TextArea", "Gui_Debug_Text_Area"));
		guiDebug->setFontName(this->_pFont->getName());
		guiDebug->setMetricsMode(Ogre::GMM_PIXELS);
		guiDebug->setPosition(5, 5);
		guiDebug->setColour(Ogre::ColourValue(0.5, 1, 1, 0.5));
		guiDebug->setDimensions(190, 40);
		guiDebug->setCharHeight(detail);
		this->panGui = new Ogre::PanelGuiElement("Debug_Panel");
		this->panGui->addChild(guiDebug);
		this->panGui->setTransparent(true);
		this->panGui->setMetricsMode(Ogre::GMM_PIXELS);
		this->panGui->setPosition(5, 5);
		this->panGui->setDimensions(220.0, 50.0);

		this->o = GAME::CGameApplication::getSingletonPtr()->getSceneManager()->createOverlay("Debug_Overlay");
		o->add2D(panGui);
		o->setZOrder(500);
		guiDebug->show();
		this->panGui->show();
		o->show();
	}

	CGameDebugFrameListener::~CGameDebugFrameListener(void)
	{
		if(panGui)
			delete panGui;
	}

	bool CGameDebugFrameListener::frameStarted(const Ogre::FrameEvent& evt)
	{
		if(this->_pWnd->isClosed())
			return false;

		return true;
	}
	bool CGameDebugFrameListener::frameEnded(const Ogre::FrameEvent& evt)
	{
		stats = &this->_pWnd->getStatistics();
		guiDebug->setCaption("Average FPS: " + Ogre::StringConverter::toString(stats->avgFPS));
		return true;
	}
I do this in that way, because i'd like to learn how to dynamically create an overlay, add panel and a few GUI Elements on it.

So, when I run my program with this class I receive an error message and program crashes with Access Violation Code (0xC0000005). I have no idea what I’m doing wrong. I’ve already tried to make an overlay script with the same parameters and use it. But nothing good happened.

Posted: Sat Feb 05, 2005 6:21 pm
by sinbad
Run it in debug mode, then you'll see where the access violation is happening.