[AD] Fix for change to allow keyboard input to non-Allegro windows on OS X (4.4)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi,

I'm afraid I've found a problem with the patch that I posted to http://www.allegro.cc/forums/thread/601965.  A deadlock can occur in the following circumstances:

1) A method is called in response to user input (e.g. a Cocoa menu selection) (this happens on the main thread, in osx_event_handler() which is called from -[AllegroAppDelegate applicationDidFinishLaunching:] with osx_event_mutex locked).

2) This method uses -[NSObject performSelector: onThread: withObject: waitUntilDone:YES] to run some code on the thread that Allegro runs the user's main() on.

3) The selector that is performed on the user main() thread opens a window (or does something else that results in the Allegro from losing focus, or "resigning key" in Cocoa jargon).

4) Cocoa then calls -[AllegroWindowDelegate windowDidResignKey:] in the user main() thread.  This tries to lock osx_event_mutex but it is already locked by the main thread, which is waiting for the performSelector call in step (2) to return.  performSelector will never return because it is waiting for the window opening code running on the user main() thread to return.

The attached patch fixes this by using a separate mutex for the osx_skip_events_processing variable instead of using osx_event_mutex for it.

Francis

Attachment: allegro-4.4-osx_skip_events_processing_mutex.diff
Description: Binary data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/