[osg-users] Question about idle event handling in the wxWidgets example

YH Zhang asmwarrior at gmail.com
Thu Oct 3 02:41:43 PDT 2019

Hi, in the \examples\osgviewerWX\osgviewerWX.cpp

I see such code snippet


void MainFrame::OnIdle(wxIdleEvent &event)
    if (!_viewer->isRealized())



This makes the frame() function call runs continuously.

I just change the code by those steps:

1, first, I comment out all the codes in the "void MainFrame::OnIdle(wxIdleEvent &event)", and this means the OnIdle just do nothing.

2, second, I add some code snippet to some event handling function like:


void OSGCanvas::OnMouseWheel(wxMouseEvent &event)
    int delta = event.GetWheelRotation() / event.GetWheelDelta() * event.GetLinesPerAction();

    if (_graphics_window.valid()) {
            delta>0 ?
            osgGA::GUIEventAdapter::SCROLL_UP :

    // those code were added by me, which force a refresh of the view
    MainFrame * f = (MainFrame *)GetParent();

    if (!f->_viewer->isRealized())



My question is: My thought was remove the idle event handling, because it waste some CPU resource to refresh the opengl window again and again. My change is try to only update the view when some true event happens. Any ideas?

Thank you!

Read this topic online here:

More information about the osg-users mailing list