Event binding woes

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

CadetUmfer
Just popping in
Just popping in
Posts: 7
Joined: Wed Feb 22, 2006 02:30
Location: Philadelphia, PA
Contact:

Event binding woes

Postby CadetUmfer » Thu Feb 23, 2006 23:43

This has been nagging me all day, hopefully someone can give me a quick answer tonight.

Code: Select all

WindowManager::getSingleton().getWindow("Chat/Wnd/Edit")->subscribeEvent(Editbox::EventTextAccepted,SendChatMessage);


This is in WinMain. SendChatMessage is defined as such

Code: Select all

bool SendChatMessage(const EventArgs& e)
and is not a member function.

Runtime exception:
Access violation reading location 0xcdcdcd08.

Any ideas?

EDIT: I can bind the event fine in Lua, so if anyone has a way to call C++ functions from Lua, that'd work too.

CadetUmfer
Just popping in
Just popping in
Posts: 7
Joined: Wed Feb 22, 2006 02:30
Location: Philadelphia, PA
Contact:

Postby CadetUmfer » Fri Feb 24, 2006 15:50

I can't seem to bind any windows to any functions in C++...I must be doing something simple wrong.

The error makes it seem like a pointer issue...
Can I not bind events if I'm using a lua script or something?

Ugh

User avatar
RenjiKage
Just popping in
Just popping in
Posts: 10
Joined: Sat Nov 26, 2005 15:56
Location: Kokubunji-shi, Tokyo-to, Japan

Postby RenjiKage » Fri Feb 24, 2006 16:05

Just write spaghetti code like this:

Code: Select all

<GetWindowRef>.subscribeEvent(CEGUI::ButtonBase::EventMouseClick,CEGUI::Event::Subscriber(&ClassX::handleSomeEvent,PtrToClassX));


You have to bind this subscriber object to the event. The subscriber object needs a pointer to a member function of class X (that's like an offset) and a pointer to an instance of class X (so that it can get the right adress to call the event handler later).

CadetUmfer
Just popping in
Just popping in
Posts: 7
Joined: Wed Feb 22, 2006 02:30
Location: Philadelphia, PA
Contact:

Postby CadetUmfer » Fri Feb 24, 2006 18:05

That's essentially how I originally had it--I just moved everything out of classes for testing.

I can edit properties for the window (such as SetText()), I can create the event subscriber, but when I subscribe, boom.

Example:

Code: Select all

Window* rwin=WindowManager::getSingleton().getWindow("Root");
Event::Subscriber subs=Event::Subscriber(&cGUIManager::handleKey,this);
rwin->subscribeEvent(Window::EventKeyDown,subsc);


is fine until the last line.

CadetUmfer
Just popping in
Just popping in
Posts: 7
Joined: Wed Feb 22, 2006 02:30
Location: Philadelphia, PA
Contact:

Postby CadetUmfer » Fri Feb 24, 2006 19:11

It's gonna be something wrong with my DLL or something (I'm using the one from the VS2k5 SDK), I just made a quick barebones testapp and I can't bind events in that either, same error. Same memory address as my main app. Unless I switch ot the release DLL, then a different addy.

Anyway, just in case someone can help me out here, I'll post some code. I'd hate to have to switch to some half-assed GUI after seeing what cegui can do.

Code: Select all

#include <windows.h>
#include <hge.h> // Graphics engine
#include "CEGUI.h"
#include "renderers/HgeRenderer/HgeRenderer.h" //Renderer

using namespace CEGUI;

HGE* hge=0;

// stuff to translate key and mouse movements--I know it works

bool handleEvent(const EventArgs &e) //test event handler
{
  return true;
}

bool HGELoop()
{
   hge->Gfx_BeginScene();
  //pass events to cegui--this works
  System::getSingleton().renderGUI();
   hge->Gfx_EndScene();
   return false;
}

int WINAPI WinMain (HINSTANCE,HINSTANCE,LPSTR,int)
{
    // hge config stuff
    HgeRenderer* myRenderer = new HgeRenderer();
    new System(myRenderer);
    SchemeManager::getSingleton().loadScheme("../datafiles/schemes/TaharezLook.scheme");
    FontManager::getSingleton().createFont("../datafiles/fonts/Commonwealth-10.font");
    System::getSingleton().setDefaultFont("Commonwealth-10");
    System::getSingleton().setDefaultMouseCursor("TaharezLook","MouseArrow");

    Window* myRoot = WindowManager::getSingleton().createWindow("DefaultWindow","root");
    System::getSingleton().setGUISheet(myRoot);

    myRoot->subscribeEvent(Window::EventMouseEnters,handleEvent);

     hge->System_Start();

   hge->System_Shutdown();
   hge->Release();

   return 0;
}

User avatar
RenjiKage
Just popping in
Just popping in
Posts: 10
Joined: Sat Nov 26, 2005 15:56
Location: Kokubunji-shi, Tokyo-to, Japan

Postby RenjiKage » Fri Feb 24, 2006 19:33

If you think that something is wrong with your DLL, just recompile CEGUI. I know it sounds kinda silly, but have you upgraded to CEGUI 0.4.1 and still use your old (0.4) CEGUI DLLs?

If your DLL is fine, then I have currently no idea or I am missing something quite obvious... I looked into my CEGUI initialization code and I am doing the same things as you do... :?

CadetUmfer
Just popping in
Just popping in
Posts: 7
Joined: Wed Feb 22, 2006 02:30
Location: Philadelphia, PA
Contact:

Postby CadetUmfer » Sat Feb 25, 2006 04:14

Recompiled every CEGUI component and now it works fine. *boggle*

BTW, what's the advantage of xerces-c over TinyXML?

User avatar
RenjiKage
Just popping in
Just popping in
Posts: 10
Joined: Sat Nov 26, 2005 15:56
Location: Kokubunji-shi, Tokyo-to, Japan

Postby RenjiKage » Sat Feb 25, 2006 04:23

Xerces-C is a more advanced XML parser. TinyXML can only validate XML itself (so that you don't have syntax errors iny our document like missing closing tags or invalid characters).

Xerces-C can validate against a DTD or an XML scheme, so it can also check if documents match with their definitions. This way, with Xerces-C you can't parse an XML file which is not a valid GUI layout or not a valid imageset file.

The problem is that Xerces-C has a memory manager that used to collide with the one of Ogre somewhat.

In the end, Xerces-C has more functionality, but TinyXML has less overhead, so the choice is entirely yours. :D


Return to “Help”

Who is online

Users browsing this forum: No registered users and 12 guests