X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a959b08869abdec7449d49e18cb069e81a3f83e6..239c2e9674c8c6b9f0fd3d6fb94e2381691651b5:/src/mac/carbon/macnotfy.cpp?ds=inline

diff --git a/src/mac/carbon/macnotfy.cpp b/src/mac/carbon/macnotfy.cpp
index a260697da0..507605510d 100644
--- a/src/mac/carbon/macnotfy.cpp
+++ b/src/mac/carbon/macnotfy.cpp
@@ -7,6 +7,10 @@
  * -------------------------------------------------------------------------
  */
 
+#include "wx/wx.h"
+
+#include "wx/mac/private.h"
+
 #include "wx/mac/macnotfy.h"
 
 const short kMaxEvents = 1000 ;
@@ -58,7 +62,6 @@ void wxMacCreateNotifierTable()
 
 void wxMacDestroyNotifierTable() 
 {
-	wxASSERT( gMacNotificationEvents.top == gMacNotificationEvents.bottom ) ;
 }
 
 wxMacNotifierTableRef wxMacGetNotifierTable() 
@@ -74,6 +77,7 @@ void wxMacAddEvent(
 	short wakeUp ) 
 {
 	wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
+	wxASSERT_MSG( handler != NULL , "illegal notification proc ptr" ) ;
 	/* this should be protected eventually */
 	short index = e->top++ ;
 	
@@ -111,21 +115,31 @@ void wxMacProcessNotifierEvents()
 //  	return ;
   	
   gInProcessing = true ;
-  while ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
+  if ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
   {
-    // consume event at bottom
-	short index = gMacNotificationEvents.bottom++ ;
-    if ( gMacNotificationEvents.bottom == kMaxEvents )
-      gMacNotificationEvents.bottom = 0 ;
-    void* data = gMacNotificationEvents.data[index] ;
-    unsigned long event = gMacNotificationEvents.events[index] ;
-	wxMacNotificationProcPtr handler =  gMacNotificationEvents.proc[index] ;
-	
-	gMacNotificationEvents.data[index] = NULL ;
-	gMacNotificationEvents.events[index] = NULL ;
-	gMacNotificationEvents.proc[index]  = NULL ;
-    
-	handler( event , data  ) ;
+    // we only should process the notifiers that were here when we entered it
+    // otherwise we might never get out...  
+	short count = gMacNotificationEvents.top - gMacNotificationEvents.bottom ;
+	if ( count < 0 )
+        count += kMaxEvents ;
+        
+    while ( count-- )
+    {
+        // consume event at bottom
+    	short index = gMacNotificationEvents.bottom++ ;
+        if ( gMacNotificationEvents.bottom == kMaxEvents )
+          gMacNotificationEvents.bottom = 0 ;
+        void* data = gMacNotificationEvents.data[index] ;
+        unsigned long event = gMacNotificationEvents.events[index] ;
+    	wxMacNotificationProcPtr handler =  gMacNotificationEvents.proc[index] ;
+    	
+    	gMacNotificationEvents.data[index] = NULL ;
+    	gMacNotificationEvents.events[index] = NULL ;
+    	gMacNotificationEvents.proc[index]  = NULL ;
+        
+        if ( handler )
+    	    handler( event , data  ) ;
+	}
   }
   gInProcessing = false ;
 }