Can't get subscribeEvent to call its functions

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

anave26
Just popping in
Just popping in
Posts: 7
Joined: Mon Jun 12, 2017 22:38

Can't get subscribeEvent to call its functions

Postby anave26 » Thu Jun 15, 2017 05:19

Hey everyone, I'm new to CEGUI and I've been working my way though the tutorials and everything works great, except I can't seem to get my windows to subscribe to events.

First off, here is the information you will undoubtedly what to know about the system:
CEGUI Log file:
14/06/2017 21:43:45 (Std) ---- Version: 0.8.5 (Build: Jun 1 2017 Debug Microsoft Windows MSVC++ 14.0 (2015) 64 bit) ----
14/06/2017 21:43:45 (Std) ---- Renderer module is: CEGUI::OgreRenderer - Official OGRE based 2nd generation renderer module. ----
14/06/2017 21:43:45 (Std) ---- XML Parser module is: CEGUI::ExpatParser - Official expat based parser module for CEGUI ----
14/06/2017 21:43:45 (Std) ---- Image Codec module is: OgreImageCodec - Integrated ImageCodec using the Ogre engine. ----
14/06/2017 21:43:45 (Std) ---- Scripting module is: None ----

Rendering: Ogre 1.9 built with boost 1.61
Windowing and Input Handling: SDL 2.0.5
OS: Window 10Pro 64bit

The relevant functions:
Initializing CEGUI:

Code: Select all

void cegui_Init(Ogre::Root* ogreRoot) {

cegui = &CEGUI::OgreRenderer::bootstrapSystem(*(ogreRoot->getRenderTarget("test")));

//Specifiy the location of CEGUI resources and set a type and group.
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("F:/Libraries/Source/CEGUI/CEGUI_0_8_5/datafiles/imagesets", "FileSystem", "Imagesets");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("F:/Programming/Test/layouts", "FileSystem", "Layouts");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("F:/Libraries/Source/CEGUI/CEGUI_0_8_5/datafiles/fonts", "FileSystem", "Fonts");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("F:/Libraries/Source/CEGUI/CEGUI_0_8_5/datafiles/looknfeel", "FileSystem", "LookNFeel");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("F:/Libraries/Source/CEGUI/CEGUI_0_8_5/datafiles/schemes", "FileSystem", "Schemes");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("F:/Libraries/Source/CEGUI/CEGUI_0_8_5/datafiles/lua_scripts", "FileSystem", "lua_scripts");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("F:/Libraries/Source/CEGUI/CEGUI_0_8_5/datafiles/animations", "FileSystem", "Animations");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("F:/Libraries/Source/CEGUI/CEGUI_0_8_5/datafiles/xml_schemas", "FileSystem", "schemas");

//Set the Default Resource Groups
CEGUI::ImageManager::setImagesetDefaultResourceGroup("Imagesets");
CEGUI::Font::setDefaultResourceGroup("Fonts");
CEGUI::Scheme::setDefaultResourceGroup("Schemes");
CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
CEGUI::WindowManager::setDefaultResourceGroup("Layouts");
CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
//Setup default group for validation schemas
CEGUI::XMLParser *parser = CEGUI::System::getSingleton().getXMLParser();
if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
      parser->setProperty("SchemasDefaultResourceGroup", "schemas");

//-------------------------------------------------------------------Set the look and Feel----------------------------------------------------------------------
CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");   
CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-10.font");

//--------------------------------------------------------------Set and Initialize Default Systems---------------------------------------------------------------
//Ensure the default font is DejaVuSans-10
CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultFont("DejaVuSans-10");
//Set the default mouse cursor
CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
}


Create a button and subscribe it to and event

Code: Select all

CEGUI::Window* eBtn;
void ceGuiTestWindowInCode() {
CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();   
CEGUI::Window* myRoot = wmgr.createWindow("DefaultWindow", "root");   
CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(myRoot);   
eBtn = wmgr.createWindow("TaharezLook/Button", "exit");
   
eBtn->setPosition(CEGUI::UVector2(CEGUI::UDim(0.43f, 0.0f), CEGUI::UDim(0.475f, 0.0f)));
eBtn->setSize(CEGUI::USize(CEGUI::UDim(0.15f, 0.0f), CEGUI::UDim(0.05f, 0.0f)));
eBtn->setText("Exit");

myRoot->addChild(eBtn);
eBtn->subscribeEvent(CEGUI::PushButton::EventClicked, exitEvent);
}


The function that should be getting called:

Code: Select all

bool exitEvent(const CEGUI::EventArgs& ) {
   cont = false;

   return false;
}


And Finally the main loop where input is injected:

Code: Select all

SDL_Event e;
float timer = 0;
//main loop
while (cont) {
   Ogre::WindowEventUtilities::messagePump();
      
   while (SDL_PollEvent(&e)) {
      if (e.type == SDL_KEYDOWN)
         cont = false;
      if (e.type == SDL_MOUSEMOTION)
         CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseMove(e.motion.xrel, e.motion.yrel);
      if (e.type == SDL_MOUSEBUTTONDOWN) {
         if(e.button.button == SDL_BUTTON_LEFT)
            CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonClick(CEGUI::LeftButton);
      }

   }
   timer = timeSinceLast();
   CEGUI::System::getSingleton().getDefaultGUIContext().injectTimePulse(timer);
   CEGUI::System::getSingleton().injectTimePulse(timer);

   root->renderOneFrame();
}


The window is created fine and the buttonWindow is displayed and the mouse cursor displays and seems to work fine. Also, when I mouse over the buttonWindow the button highlights so it seems to recognize the mouse is over it. The injectMouseButtonClick(DEGUI::LeftButton) line is called when the left mouse button is clicked, however, the exitEvent( const CEGUI::EventArgs&) function is never called (Or at least it never executes).

I've tried creating a function pointer and using that to register the event with the same result.
I've tried using the Event::Subscriber(exitEvent) same result.
I've tried encapsulating the exitEvent in a function and calling it exactly as the tutorial Practive A push button show... same result.
I've even tried creating the test GUI with a Layout file and going at it that way... same result. (This is a great feature by the way... you guys rock!) :D

I don't know if this is some weird interaction with SDL 2.0 (though I can't see what that would be) or If I'm just missing something but I've been tilting at this particular windmill off an on for three days now and I'm totally out of ideas. Any help would be much appreciated.

Thanks.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Can't get subscribeEvent to call its functions

Postby Ident » Thu Jun 15, 2017 07:03

Indeed that seems odd. It looks like you do everything right at first glance: you update both context and system, you said the injection is called correctly. You checked that the mouse position is right.

Hmm.

Have you tried adding an editbox and see if it reacts to your click? The caret should appear if it receives focus.

Also, are you aware we have a minimal working base for SDL2 ready in the repository? You can find it in the folder application_templates, it is called "SDL2.cpp" and you can also run this if you create the project using CMake. You might want to see what is different between that and your solution. This SDL2 setup was checked by devs to be working.
CrazyEddie: "I don't like GUIs"

anave26
Just popping in
Just popping in
Posts: 7
Joined: Mon Jun 12, 2017 22:38

Re: Can't get subscribeEvent to call its functions

Postby anave26 » Fri Jun 16, 2017 07:36

Okay, so it looks like it is just mouse button events that don't work. Mouse motion injection is fine and input from the keyboard seems to be working okay when injected into CEGUI... Also, the edit box does not get the caret when I click on it.

I made a couple of adjustments using the minimal SDL2 recommend by Ident, but I'm still getting the same behavior. I haven't started digging into the internals of CEGUI / Ogre / SDL yet but I'm thinking the problem may actually be with SDL doing the windowing while using an Ogre renderer, does that even make sense? I'm a relative baby when it comes to graphical programming, other than an Intro to 3d graphics I had back at university, I have minimal experience.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Can't get subscribeEvent to call its functions

Postby Ident » Fri Jun 16, 2017 08:31

Graphical programming itself has nothing to do with this: even with nothing rendered, you should get the events if you click in the right area ;) The problem lies, as you correctly said, somewhere in the input handling.

The fact that an editbox receives no caret means that the problem is a more general one, not just related to how you want to use your event.

Can you step into injectMouseButtonClick and see what value you get for the mouse button? You said it is called, but are we sure it receives the right value? :P
CrazyEddie: "I don't like GUIs"

anave26
Just popping in
Just popping in
Posts: 7
Joined: Mon Jun 12, 2017 22:38

Re: Can't get subscribeEvent to call its functions

Postby anave26 » Fri Jun 16, 2017 21:22

Okay, of course you're correct. I'm just getting frustrated and taking shots in the dark. It's been a while since I worked on something outside my comfort zone.

Anyway, tracing the execution from the injectMouseButtonClick call it looks to me like the system identifies the hit on the child button (hitsTestRectValid is set to true and a pointer to the child is returned from Window.cpp) also, the injected mouse position is correct, but the fireEvent seems to be called with null parameters. This may not have anything to do with anything but it looks odd to me. Right after this fireEvent function is called the injectMouseButtonClick function returns as false and the main loop continues.
Image

Also, the guiContext of the ma.window is null

Thanks for taking the time. :D

anave26
Just popping in
Just popping in
Posts: 7
Joined: Mon Jun 12, 2017 22:38

Re: Can't get subscribeEvent to call its functions

Postby anave26 » Fri Jun 16, 2017 21:27

Sorry, I didn't answer your question... the Mouse button sent to the injectMouseButtonClick is listed as LeftButton (0) and stored in the ma struct as such.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Can't get subscribeEvent to call its functions

Postby Ident » Fri Jun 16, 2017 21:45

Ok, again it sounds like you did everything right. Although i dont know what to think about the null-parameters in fireEvent- i can't tell if this is relevant or not from afar. In fact i would have to put hands on this by myself to tell what exactly this means.


Have you tried actually running the SDL2 application template? Afaik, to run it you just need to point cmake to your SDL2 lib and generate a cegui solution with that, and then run it with the dlls in place. If you do that you can check if you get events properly there. It is already all set up with a simple window to run there so you should see if things work, without having to make changes. You should be able to drag the framewindow in the demo there. It is really not too much work to get this to run and you will have an application to compare your setup with. From there on you can step by step add stuff like you did in your application and see from when on it breaks.
CrazyEddie: "I don't like GUIs"

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Can't get subscribeEvent to call its functions

Postby Ident » Fri Jun 16, 2017 21:48

Btw I just noticed you run in x64. Are you sure you are not mixing x86 with x64 anywhere (dlls) ? This can lead to fuckups, just as mixing debug and release dlls can.
CrazyEddie: "I don't like GUIs"

anave26
Just popping in
Just popping in
Posts: 7
Joined: Mon Jun 12, 2017 22:38

Re: Can't get subscribeEvent to call its functions

Postby anave26 » Sat Jun 17, 2017 06:03

Yeah, that occurred to me as well but I double checked all the other resources and they are all x64 versions. Interestingly enough, when I run more or less the same code but using OSI for inputs instead of SDL everything works as expected. Of course I'm not using SDL for windowing then so there are some differences behind the scenes to be sure. I'm working on building the SDL/CEGUI application templates now... but I suspect those will work fine as well. Assuming that is the case, the only thing I can figure is there is some error I've introduced in the interaction between the three that is causing issues. I'm digging though the ogre docs / samples to see if I fouled something up with the external windowing...

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Can't get subscribeEvent to call its functions

Postby Ident » Sat Jun 17, 2017 08:09

Wow this seems so incredibly odd. I mean you say you inject the mouse inputs into CEGUI properly. The same way as it would occur with OIS. Then how can it be that the result is any different? It is not like CEGUI knows anything about the window handle (except for maybe the Renderer). If injecting the same, the result should be the same. And you inject time pulses the same way, right?
CrazyEddie: "I don't like GUIs"

anave26
Just popping in
Just popping in
Posts: 7
Joined: Mon Jun 12, 2017 22:38

Re: Can't get subscribeEvent to call its functions

Postby anave26 » Sat Jun 17, 2017 14:31

Yeah, Time pulses are the same, the only real difference I can see is that I allow Ogre to create the window when using OIS where as I have to use an external window handle with SDL (where SDL creates the window). In both cases Ogre still builds the renderer though so... I can't make any sense out of it... As you say, CEGUI doesn't know anything about the window handle and even if it did... it seems to correctly identify the button click so, I'm pretty confused. I'm going to dig into this a little more later. I'll post when identify anything new.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Can't get subscribeEvent to call its functions

Postby Ident » Sat Jun 17, 2017 16:58

Whenever such things happen it is typically something blatantly obvious in hindsight or something related to configuration mistakes / wrong libs combined. As of now I cant make any sense of it either.
CrazyEddie: "I don't like GUIs"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 27 guests