Problem with nuiGLUTBridge/nuiInit

Added by Christoph Lassnig 5 months ago

Hey guys, I'd like to use the NUI library for a GLUT-Project I started, but I cannot get it to work.
When I call nuiInit(NULL, NULL) (in the tutorials you wrote nuiInit(NULL) but that does not work with the newest headers, I think), there appears the following error on the console:

FT_Stream_EnterFrame: invalid i/o; pos = 0x0, count = 148, size = 0x41
FT_Stream_ReadAt: invalid read; expected 128 bytes, got 65

I am using Microsoft Visual Studio 2008 on Win7 and compiled the nui3.lib that I link with my glut-Project. The problem seems not to be related to the glut-lib, cause when I just have the nuiInit and nuiUninit functions in my main, the error occurs anyway. Now when i start the glutMainLoop I just see a black window. I did not call the Display function of the nuiGLUTBridge in my display-callback and it works when I comment out the nuiInit() function.

Can anyone help?

screen.png - Console screenshot (264.5 KB)


Replies

RE: Problem with nuiGLUTBridge/nuiInit - Added by Sebastien Metrot 5 months ago

Hi Christoph,

I have just tried the example code in nui3/examples/testGLUTIntegration and it works both on Win32 and OSX for me. I have downloaded the GLUT libs for Windows here: http://www.xmission.com/~nate/glut.html . I have put the header and lib in the nui3/examples/testGLUTIntegration/GL directory and the dll in the windows/system32 directory (you can also put it next to the executable if you'd rather not pollute your system). I build the example with Visual Studio 2008 (with the latest service pack installed) on Windows 7 and it works great. Can you try that example first and let me know if it works?

Thanks!

Sebastien

RE: Problem with nuiGLUTBridge/nuiInit - Added by Christoph Lassnig 5 months ago

Hey, thanks for the fast reply.

I already tried to compile the VS2008 File of the testGLUTIntegration and it worked fine. Maybe there was a problem when I first compiled the nui3.lib?

RE: Problem with nuiGLUTBridge/nuiInit - Added by Christoph Lassnig 5 months ago

Okay I now tried it out on Linux and after I kinda "hacked" the nuiGLUTBridge.h it works on X11. (Was there any kind of intention to forget to check if we are on X11 system? Had to insert a #ifndef X11 around BuildOpenGLFromExisting)
But I recently ran into another problem, maybe because I just do not yet understand how the API works... The problem is, that I have no idea how I can get the signals that should get posted if you click on buttons when a GlutBridge is involved. A simple aproach like that one in the tutorials result in a segmentation fault when I try to connect the EventSink with a function. Don't you have any kind of deeper information on the API written down somewhere? For what I've seen and tried out I must say I really like the API, but I think it's really hard to get more complex tasks working.

The old issue with the vs2008 project might have been my fault, I will try out some things once I get my hands back to my windowsmachine, which could take for a week or so.

RE: Problem with nuiGLUTBridge/nuiInit - Added by Sebastien Metrot 5 months ago

Hum, there is no reason other than lack of time for the lag in the linux version. We try to fix the builds as often as possible but our main dev platforms now are Windows and Mac/iPhone based. Don't hesitate to let us know when you find something strange on Linux. Oh, that and patches are usually welcome :-).

Can you post the code you're using to link the buttons to a callback so I can help you on that?

nuiEvents:
you can declare an event anywhere by declaring an nuiEventSource or nuiSimpleEventSource in your class interface. Most of the time they are public attributes so that anyone can be bound to them. When you want to trigger that event you just have to use the () operator:

1 nuiEventSource bleh; // somewhere in your class interface...
2 ...
3 bleh(); // this will trigger the event and call callbacks.

To bind a callback you need to have a special event routing object named an event sink (nuiEventSink). nuiEventSink is templated on the class that holds the callback method. For example if you want to use the method OnTriggered(..) of the class MyWidget, the routing object must be defined as this:

1 nuiEventSink<MyWidget> mEventSink;

The callback can only have the following signature:

1 bool OnTriggered(const nuiEvent& rEvent);

Now this is how you bind the source to the callback:

1 mEventSink.Connect(pButton->Activated, &MyWidget::OnTriggered);

You can add a void* parameter to the Connect method as a user value. This parameter will be passed to your callback in the nuiEvent reference argument (rEvent.mpUser).

One last point:
nuiEventSink needs to know what object instance will be the destination of the events, this is done at construction time.

To summarize, here is a little sample class that binds one of its methods as a callback to a button's Activated event source (beware, I type all the code in a browser window ;-) ):

 1 class MyStuff
 2 {
 3 public:
 4   MyStuff(nuiButton* pButton) : mEventSink(this)
 5   {
 6     mEventSink.Connect(pButton->Activated, &MyStuff::OnButtonActivated);
 7   }
 8 
 9   bool OnButtonActivated(const nuiEvent& rEvent)
10   {
11     NGL_OUT(_T("Let drop some text to the console to show that everything is alright...\n"));
12   }
13 private:
14   nuiEventSink<MyStuff> mEventSink;
15 };

I hope this helps (may be I should turn that into a wiki page?).

Cheers,

Sébastien

RE: Problem with nuiGLUTBridge/nuiInit - Added by Loïc Berthelot 5 months ago

Hey Guys,

I'ld like you to know that there is a nui3 development documentation in the wiki :
http://redmine.libnui.net/projects/libnui/wiki/

The end of the first chapter is dealing with events:
http://redmine.libnui.net/projects/libnui/wiki/TutorialCommon

And there are a bunch of tutorials in the nui source directory that shows a lot of examples using events and signals.

Let me know with you need anything else...

cheers,
loïc.

RE: Problem with nuiGLUTBridge/nuiInit - Added by Christoph Lassnig 5 months ago

Sebastien Metrot wrote:

Hum, there is no reason other than lack of time for the lag in the linux version. We try to fix the builds as often as possible but our main dev platforms now are Windows and Mac/iPhone based. Don't hesitate to let us know when you find something strange on Linux. Oh, that and patches are usually welcome :-).

When I try to compile the project with gcc with global define -D LINUX, then I get the error that BuildOpenGLFromExisting was not declared. After putting a #ifndef X11 into the class header it compiles and the program starts. But then it tells me

context: Error: No X connection

Do I miss another option like -D GLUT or whatever so that the thing does not try to connect to X11 (because I guess, that nui tries to connect to the GLUT environment). It's just cosmetics, because the error has no effect on the application. One more thing though, when I start the program on Linux, I get

create string codec (0x884c368) from wchar_t(41) to UTF-8(40) kernel: Init (0 parameter) NUI_RESOURCE_PATH: /usr/share/
and then after about 10 seconds I get messages like FontManager: add new font in database '/usr/share/fonts/misc/olgl14.pcf.gz' Scaning font '/usr/share/fonts/misc/olgl19.pcf.gz' face 0 0 glyphs

Why does it last so long for the program to startup? Can I accelerate that?

// change in nuiGLUTbridge.h, Line 29
#ifdef WIN32
    BuildOpenGLFromExisting(NULL, NULL);

#else
    #ifndef _X11_
    BuildOpenGLFromExisting(NULL, aglGetCurrentContext());
    #endif
#endif

Sebastien Metrot wrote:

Can you post the code you're using to link the buttons to a callback so I can help you on that?

Of course:

// GUI.h
public:
[...]
bool OnToggleWireframe(const nuiEvent& rEvent);

private:
nuiEventSink<GUI>   _EventSink;    

// GUI.cpp
// I use SetElements, because I think that OnCreation() did nothing or I missed something
void GUI::SetElements(void)
{
    EmptyTrash();
    nuiVBox* Box = new nuiVBox(2);
    nuiButton* B1 = new nuiButton(_T("Toggle Wireframe"));
    nuiGrid* Grid = new nuiGrid(2, 2);
    nuiButton* B2 = new nuiButton(_T("Increase stepping"));
    nuiButton* B3 = new nuiButton(_T("Toggle Projection"));
    nuiButton* B4 = new nuiButton(_T("Button4"));
    nuiButton* B5 = new nuiButton(_T("Exit"));
    Grid->SetCell(0, 0, B2);
    Grid->SetCell(0, 1, B3);
    Grid->SetCell(1, 0, B4);
    Grid->SetCell(1, 1, B5);
    Box->SetCell(0, B1);
    Box->SetCell(1, Grid);
    _EventSink.Connect(B1->Activated, &GUI::OnToggleWireframe);
    this->AddChild(Box);

}

Thanks for your help.

RE: Problem with nuiGLUTBridge/nuiInit - Added by Sebastien Metrot 5 months ago

Ok,

Can you make sure that _EventSink is well initialized to this in the GUI constructor?

Also can you post a debugger calstack/trace of the crash please?

I'll look into the linux problem tonight from my home computer that has a better Linux installation than my laptop.

Cheers,

Sebastien

RE: Problem with nuiGLUTBridge/nuiInit - Added by Christoph Lassnig 5 months ago

Okay I think I got that right:

FontManager: add new font in database '/usr/share/fonts/misc/olgl19.pcf.gz'
context: Error: No X connection
font : Initializing FreeType library
font : Initializing FreeType cache (10 KB)
font : Loading logical font at 0xb7ac2938 (face 0, 49224 bytes)
Program received signal SIGSEGV, Segmentation fault.
0xb75c5cbd in nuiEventTargetBase::Connect (this=0x8ee1afc, rSource=..., rTargetFunc=..., pUser=0x0) at /home/raven/svn/nui3/src/Base/nuiEvent.cpp:194
194 rSource.Connect(this);
(gdb) backtrace
0 0xb75c5cbd in nuiEventTargetBase::Connect (this=0x8ee1afc, rSource=..., rTargetFunc=..., pUser=0x0) at /home/raven/svn/nui3/src/Base/nuiEvent.cpp:194
1 0x08052201 in nuiEventSink<GUI>::Connect (this=0x8ee1afc, rSource=..., pTargetFunc=0x8050fd8 <GUI::OnToggleWireframe(nuiEvent const&)>, pUser=0x0)
at /usr/include/nui3/nuiEvent.h:125
2 0x08050f7b in GUI::SetElements (this=0x8ee0318) at GUI.cpp:153
3 0x08050ae7 in GUI::EnterMainLoop (this=0x8ee0318) at GUI.cpp:124
4 0x0804fbfe in main (argc=1, argv=0xbffff904) at main.cpp:14
(gdb) frame 0
#0 0xb75c5cbd in nuiEventTargetBase::Connect (this=0x8ee1afc, rSource=..., rTargetFunc=..., pUser=0x0) at /home/raven/svn/nui3/src/Base/nuiEvent.cpp:194
194 rSource.Connect(this);
(gdb) info frame
Stack level 0, frame at 0xbffff720:
eip = 0xb75c5cbd in nuiEventTargetBase::Connect (/home/raven/svn/nui3/src/Base/nuiEvent.cpp:194); saved eip 0x8052201
called by frame at 0xbffff750
source language c++.
Arglist at 0xbffff718, args: this=0x8ee1afc, rSource=..., rTargetFunc=..., pUser=0x0
Locals at 0xbffff718, Previous frame's sp is 0xbffff720
Saved registers:
ebx at 0xbffff710, ebp at 0xbffff718, esi at 0xbffff714, eip at 0xbffff71c
(gdb) info locals
PRETTY_FUNCTION = "void nuiEventTargetBase::Connect(nuiEventSource&, const nuiDelegateMemento&, void*)"
pLink = 0x9b5e660
rLinkList = @0xb75c5bec
(gdb) info args
this = 0x8ee1afc
rSource = @0x90a9984
rTargetFunc = @0xbffff734
pUser = 0x0

I'm initializing the EventSink with the Class-Constructor

// GUI.cpp
GUI::GUI() : _EventSink(this)
{
    _hData = NULL;
    gpInterface = this;
}

RE: Problem with nuiGLUTBridge/nuiInit - Added by Sebastien Metrot 5 months ago

I still don't understand the crash you are experiencing but at least I have fixed the GLUT bridge for Linux/X11.

Let me know if it works fine for you!

RE: Problem with nuiGLUTBridge/nuiInit - Added by Christoph Lassnig 5 months ago

Just downloaded latest SVN snapshot and tried it out, at least it compiles without problems, though I'm still getting the "context: Error: No X connection" warning that shows up on the startup. But the window is rendered fine and there are no problems with the implemented buttons.

The issue when connecting to the button-event is still remaining and it bothers me. I'll try to modify the nui-event-sourcecode to get some further debug-info. Thanks anyway!

RE: Problem with nuiGLUTBridge/nuiInit - Added by Christoph Lassnig 5 months ago

Now that's interesting... I just copied the files I tried out on Linux to my Windows machine and guess what - there is NO error happening when starting up the program. The button's are correctly connected to the functions and it all works fine. So the error might be Linux-related...