Function nanogui::mainloop

Function Documentation

void nanogui::mainloop(int refresh = 50)

Enter the application main loop.

Remark

Unfortunately, Mac OS X strictly requires all event processing to take place on the application’s main thread, which is fundamentally incompatible with this type of approach. Thus, NanoGUI relies on a rather crazy workaround on Mac OS (kudos to Dmitriy Morozov): mainloop() launches a new thread as before but then uses libcoro to swap the thread execution environment (stack, registers, ..) with the main thread. This means that the main application thread is hijacked and processes events in the main loop to satisfy the requirements on Mac OS, while the thread that actually returns from this function is the newly created one (paradoxical, as that may seem). Deleting or join()ing the returned handle causes application to wait for the termination of the main loop and then swap the two thread environments back into their initial configuration.

Parameters
  • refresh: NanoGUI issues a redraw call whenever an keyboard/mouse/.. event is received. In the absence of any external events, it enforces a redraw once every refresh milliseconds. To disable the refresh timer, specify a negative value here.

  • detach: This parameter only exists in the Python bindings. When the active Screen instance is provided via the detach parameter, the mainloop() function becomes non-blocking and returns immediately (in this case, the main loop runs in parallel on a newly created thread). This feature is convenient for prototyping user interfaces on an interactive Python command prompt. When detach != None, the function returns an opaque handle that will release any resources allocated by the created thread when the handle’s join() method is invoked (or when it is garbage collected).