(no bug) Prob. when IRRlicht is used with wxWidget

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

(no bug) Prob. when IRRlicht is used with wxWidget

Post by christianclavet »

Hi, I think thoses problems could affect Irrlicht response and perhaps could NOT be bugs, I'm just asking because I've had weird behaviors coming from the IRRlicht window. This as all been experimented with Irrlicht 1.7.2 and MSVC on Windows Vista.
I was able to use IRRlicht inside a WxWidget application. wxWidget recommend that we use their "event loop" and refresh our application.
I tried to use their recommendation when I started implementing wxWidget for the IRR Rpg Builder project:
http://irrrpgbuilder.sourceforge.net/fo ... p=291#p291

-- When wxWidget drive the main loop:
Using their recommendation, the main loop is done inside WxWidget and I'm intercepting events and forwarding them to IRRlicht (mouse and keyboard events), Irrlicht is refreshed by a timer event.

But I had this problems: (my biggest problem so far)
- animated meshes don't animate, they only move to their first frame. (they still move on the screen but their animation is not playing)
- The Irrlicht scroller GUI is working but the slider GUI element is not receiving the mouse events and is not working, but the button arrows are still functionnal.

Theses problems are related to how IRRlicht received the events from wxWidget and "might" not be bugs. (If someone have an idea how to set the events to be received properly by IRRlicht it would be great)
- I had weird issues with the way the keyboard event were received by IRRlicht, all the letters are received as capital letters. (perhaps I need to process them further before sending them to IRRlicht?)
- Mouse events seem to work, but a combined mouse+keyboard event is not received properly (keyboard event is not received)

--When IRRlicht is using it's own game loop and "refresh" wxWidget:
I found out by some tests that IRRlicht seem to work properly, if instead I run the application in a game loop (inside IRRlicht). It look like IRRlicht magically is getting the proper events, the animations plays, the GUI slider is working also. I checked further by disabling the forwarding of events from wxWidget and IRRlicht was still receiving mouse and keyboard events...

Look like IRRlicht for some reasons is connecting directly to the OS? I don't know, but it work better, and I've set up the application this way. To have wxWidget receive events for it's own GUI, I've added the wxYield() inside my Irrlicht game loop. The only problem is that is considered "bad" by wxWidget.

-- Other problems caused when IRRlicht is used in a window:
There is also one problem when IRRlicht is used inside wxWidget (could also be inside a window application or other types I suppose)

- The returned device screen size is wrong. It should return the window size IRRlicht is placed.

And caused thoses problems:
- IRRlicht GUI positions based on the screen are placed incorrectly
- IRRlicht GUI that are trying to use "absolute" clipping rectangle position are returning wrong values. (I found out that using the "clientrect" seem to return a more coherent value.
- IRRlicht cameras don't have the proper aspect ratio (I think its because of the wrong information about the display size)
Last edited by christianclavet on Thu Mar 31, 2011 5:14 pm, edited 1 time in total.
TCM
Posts: 53
Joined: Mon May 24, 2010 9:29 pm

Post by TCM »

- animated meshes don't animate, they only move to their first frame.
You must add a tick call, just before beginScene:

Code: Select all

GetIrrDevice()->getTimer()->tick();
- IRRlicht cameras don't have the proper aspect ratio (I think its because of the wrong information about the display size)
Add this:

Code: Select all

void CIrrWindow::OnSize(wxSizeEvent &event)
{
	float w=GetClientSize().GetWidth();
	float h=GetClientSize().GetHeight();


   fRatio = (float)w/(float)h;
   if ( irrWrapperDevice )
   {
      irr::video::IVideoDriver *driver=irrWrapperDevice->GetVideoDriver();
	
      if ( driver )
      {   
		 const core::dimension2d<irr::u32> dim(w, h);
		 driver->OnResize( dim );
         if ( irrCameraCurrent )
            irrCameraCurrent->setAspectRatio( fRatio );
         if ( !m_Timer.IsRunning() )
            Update();
      }
   }
   event.Skip();
}

I hope this helps.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

@christianclavet: could you by anyhow give me a simple proper sample how to run irrlicht inside wxWidgets? (that would work on linux)
Working on game: Marrbles (Currently stopped).
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Thanks TCM! I did not know about the "tick"! Great! I will keep what I've done for the "main" window of the application, but for other tools using 3D windows, this will be very helpful! Do you think that could solve the event problem?

Cool! For the camera, my solution is almost the same in code as yours! :)

For the display size, I checked more why the display was distorted and the device size at initialisation (When I define all the "ingame" IRRlicht guis) is 20x20. I fixed it by defining my "own" size at initialisation.

Once initialised the display size report ok. (I think wxWidget init IRRlicht in 20,20 then stretche it to match the window after being initialised)

serengeor, I'm developping the windows version for IRR RPG Builder, but Andres (the originator of the project) will port the windows version to Linux when he have the time. Check the forum when he does.

Meanwhile, have you tried to use a wxWidget demo project and added Irrlicht to it for testing? There is a lot of libraries to add to the project to start a wxProject. The place I had the most trouble was to give IRRlicht the proper window handle.

I've found a code that initialize Irrlicht inside Linux, but I've not tested it (Im using windows only) Perhaps you could check and try it (Check the LINUX define condition in this code):

If someone have the time and skills on Linux, having defines like that in the Example14 (Win32Window), that could open a window on Linux would be really nice...

Code: Select all

void wxIrrlicht::InitIrr(irr::SIrrlichtCreationParameters* init_params) {
    SIrrlichtCreationParameters params;
    params.DriverType = EDT_OPENGL;

    SIrrlichtCreationParameters* actual_params = init_params ? init_params : &params;
    dimension2d<s32> irrSize(GetClientSize().GetX(), GetClientSize().GetY());
    actual_params->WindowSize = irrSize;

#ifdef LINUX
    wxStaticText* pnl = new wxStaticText(this, -1, wxEmptyString);
    pnl->SetBackgroundStyle(wxBG_STYLE_CUSTOM);

    GtkWidget* handle = pnl->GetHandle();
    if (!handle)
        return;
    XID xHandle = GDK_WINDOW_XWINDOW(handle->window);
    Display* mDisp = GDK_WINDOW_XDISPLAY(handle->window);
    stringc dName = (long)mDisp;
    dName += ':';
    dName += (int)xHandle;
    actual_params->WindowId = (long)dName.c_str();
#else
    actual_params->WindowId = reinterpret_cast<void *>(pnl->GetHandle());
#endif

    m_pDevice = createDeviceEx(*actual_params);

    if (!m_pDevice) {
        throw "Can't create Irrlicht device!";
	}//if

	m_pDriver = m_pDevice->getVideoDriver();
	m_pSceneManager = m_pDevice->getSceneManager();
	m_pGuiEnvironment = m_pDevice->getGUIEnvironment();

    OnCreateScene();

    m_pDriver->OnResize(irrSize);
}//InitIrr()
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

If someone have the time and skills on Linux, having defines like that in the Example14 (Win32Window), that could open a window on Linux would be really nice...
Yeah, this should be made for all major OS's, not just M$.
Working on game: Marrbles (Currently stopped).
TCM
Posts: 53
Joined: Mon May 24, 2010 9:29 pm

Post by TCM »

I am not sure what wxWidget is your irrLicht window. Is it a wxControl or a wxWindow? You must make sure that the control or window in which you have the irrlicht 3d window is having the focus. Otherwise it simply does not receive the messages, since it does not have the focus. You can give it the focus this way:

Code: Select all

this->SetFocus();
where this is the control (or window) handle.

Also, you can also handle the messages in the main wxWindows class.

I also had problems with the main irrlicht handle . To create the wxWindow you need the irrlicht handle, and to create the irrlicht window, you need the handle to the window. I tried several ways, i still get a memory leak. Do you experience something similar, or you managed to get it working fine?
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

HI, TCM.

I confirm the memory leak, Each time I close the application I get MSVC complaining about a memory leak. I build the editor with defines (wxWidget) or plain IRRlicht. There is no report of any leak for the plain Irrlicht version. So I assume it's related on how wxWidget close the application. (As you mentionned it seem that it doesnt want to let go Irrlicht ressources).

If someone find a solution for this let us know..
gabdab
Posts: 42
Joined: Fri May 12, 2006 5:11 pm

Re: (no bug) Prob. when IRRlicht is used with wxWidget

Post by gabdab »

What is the size of the wxwidgets related libraries once included ?
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: (no bug) Prob. when IRRlicht is used with wxWidget

Post by christianclavet »

Hi, It depend on the libraries your need to use with wxWidget as it separated in several libraries. For what I needed on IRB the .lib files goes over 30 megabytes...
The final compiled application is about 3 megabytes (wxWidget libs are build as static libraries on my project). I should have updated the thread, I fixed the leak but was done so long ago that I don't remember what I've done! The thing I understand now is that Irrlicht must be go into the wxWidget loop. Doing the game loop inside Irrlicht will cut of most of the events.
gabdab
Posts: 42
Joined: Fri May 12, 2006 5:11 pm

Re: (no bug) Prob. when IRRlicht is used with wxWidget

Post by gabdab »

Hi,
I asked wxWidgets libs size to compare with Qt libs once included in project.
For me including Qt (similar to wx for some aspects) is the same : 34 Mb.
Same with Qt , irrlicht loop inside Qt loop ..
Post Reply