- Version of CS : 1.2
- Version of winlibs package (if on windows) : 1.2_002
- Operating system : Windows XP SP2
- Compiler : Visual studio 2008 Express
Hi,
I'm new to CS and I have again a problem...
I have followed some tutorials and subscribing an event to a pushButton seems easy. It works well when the code is in the 'main' csApplicationFramework, but when I want to change the subscribing to another class, it does not work no more.
Here is the code (which works) in the main class:
csRef<iCEGUI> cegui = csQueryRegistry<iCEGUI> (GetObjectRegistry());
CEGUI::WindowManager* winMgr = cegui->GetWindowManagerPtr ();
CEGUI::Window* btn = winMgr->getWindow("Tools/Quit");
btn->subscribeEvent(CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&GameEditor::OnExitButtonClicked, this));
And here is the code (which do not works) in another class:
csRef<iCEGUI> cegui = csQueryRegistry<iCEGUI> (objectRegistry);
CEGUI::Window* btn = winMgr->getWindow("Tools/Quit");
btn->subscribeEvent(CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&Gui::OnExitButtonClicked, this));
You can notice that there isn't a big difference between the two. This is why I don't understand the problem.
The method is declared public in the 2 classes. Here is the code of the non working class
Header:
#ifndef __GAME_EDITOR_GUI_H__
#define __GAME_EDITOR_GUI_H__
#include <crystalspace.h>
#include "ivaria/icegui.h"
#include <CEGUI.h>
class Gui
{
public:
bool Initialize(iObjectRegistry* objectRegistry);
void Draw();
bool OnExitButtonClicked (const CEGUI::EventArgs& e);
private:
csRef<iCEGUI> cegui;
iObjectRegistry* objectRegistry;
};
#endif // __GAME_EDITOR_GUI_H__
source:
#include <CEGUIWindowManager.h>
#include "Gui.h"
bool Gui::Initialize(iObjectRegistry* objectRegistry)
{
//this->objectRegistry = objectRegistry;
//Load and initialize Cegui plugin
cegui = CS_QUERY_REGISTRY (objectRegistry, iCEGUI);
if (!cegui) {
return false;
}
if(!cegui->Initialize()) {
return false;
}
cegui->GetLoggerPtr ()->setLoggingLevel(CEGUI::Informative);
//Change directory to ice directory
csRef<iVFS> vfs = CS_QUERY_REGISTRY (objectRegistry, iVFS);
vfs->ChDir ("/PremiersAges/gui/");
//Load a scheme
cegui->GetSchemeManagerPtr ()->loadScheme("ice.scheme");
//define cursor
cegui->GetSystemPtr ()->setDefaultMouseCursor("ice", "MouseArrow");
//Defines font
CEGUI::Font* font = cegui->GetFontManagerPtr ()->createFont("FreeType", "Vera", "/fonts/ttf/Vera.ttf");
font->setProperty("PointSize", "10");
font->load();
//setup CEGUI callback functions
CEGUI::WindowManager* winMgr = cegui->GetWindowManagerPtr ();
// Load layout and set as root
CEGUI::Window* sheet = winMgr->loadWindowLayout("ice.layout");
csRef<iCEGUI> cegui = csQueryRegistry<iCEGUI> (objectRegistry);
CEGUI::Window* btn = winMgr->getWindow("Tools/Quit");
btn->subscribeEvent(CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&Gui::OnExitButtonClicked, this));
return true;
}
void Gui::Draw()
{
cegui->Render ();
}
bool Gui::OnExitButtonClicked (const CEGUI::EventArgs&)
{
return true;
}
The error is an access violation and occurs on this line :
CEGUI::Event::Subscriber(&Gui::OnExitButtonClicked, this)
Please help me !!
Regards,
Rage