Function nanogui::mainloop¶
Defined in File common.h
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 orjoin()
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 everyrefresh
milliseconds. To disable the refresh timer, specify a negative value here.detach
: This parameter only exists in the Python bindings. When the activeScreen
instance is provided via thedetach
parameter, themainloop()
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. Whendetach != None
, the function returns an opaque handle that will release any resources allocated by the created thread when the handle’sjoin()
method is invoked (or when it is garbage collected).