[vtkusers] Window events on Mac OS X
Sean McBride
sean at rogue-research.com
Mon Aug 4 11:20:57 EDT 2008
On 8/1/08 1:21 PM, Peter Eastman said:
>I'm working on a library that uses VTK for visualization. For a
>complicated set of reasons that I can go into if you really want,
>running an event loop on the main thread is out of the question. The
>main thread is getting used for lots of things other than handling
>events, and there's nothing I can do to change that.
You're probably out of luck then. :( On OS X, most all event loop and
drawing code must be done on the main thread. Doing otherwise is
swimming upstream, but doable to some extent. Have you looked at
Apple's docs on this topic, such as the "Threading Programming Guide"?
>As a workaround, every time we call Render(), we do a quick check for
>any events that have occurred since the last render and process them
>there. We have three different versions of the code to do this for
>Windows, Mac, and Linux. It's quoted below.
>#ifdef VTK_USE_CARBON
> EventRef theEvent;
> EventTargetRef theTarget;
> theTarget = GetEventDispatcherTarget();
> while (ReceiveNextEvent(0, NULL, kEventDurationNoWait, true,
>&theEvent) == noErr) {
> SendEventToEventTarget(theEvent, theTarget);
> ReleaseEvent(theEvent);
> }
>#endif
Are you calling the above code on a non-main thread? If you look at
CarbonEventsCore.h you'll see that SendEventToEventTarget() is _not_
thread safe.
--
____________________________________________________________
Sean McBride, B. Eng sean at rogue-research.com
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
More information about the vtkusers
mailing list