From 9611686694f0449c7f7ced2e0badad9f04a22ea5 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 10 Dec 2006 13:08:42 +0000 Subject: [PATCH] adding an autorelease capability (got weird crashes when deleting tools from a toolbar otherwise) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43893 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/carbon/app.h | 4 ++++ src/mac/carbon/app.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/wx/mac/carbon/app.h b/include/wx/mac/carbon/app.h index 0b253025bf..492a713004 100644 --- a/include/wx/mac/carbon/app.h +++ b/include/wx/mac/carbon/app.h @@ -75,6 +75,10 @@ public: void MacSetCurrentEvent( WXEVENTREF event , WXEVENTHANDLERCALLREF handler ) { m_macCurrentEvent = event ; m_macCurrentEventHandlerCallRef = handler ; } + // adding a CFType object to be released only at the end of the current event cycle (increases the + // refcount of the object passed), needed in case we are in the middle of an event concering an object + // we want to delete and cannot do it immediately + void MacAddToAutorelease( void* cfrefobj ); public: static wxWindow* s_captureWindow ; static long s_lastModifiers ; diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index e997cc3e1b..8c52e9f221 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -1231,6 +1231,14 @@ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr ) // Override to process unhandled events as you please } +CFMutableArrayRef GetAutoReleaseArray() +{ + static CFMutableArrayRef array = 0; + if ( array == 0) + array= CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks); + return array; +} + void wxApp::MacHandleOneEvent( WXEVENTREF evr ) { EventTargetRef theTarget; @@ -1246,6 +1254,13 @@ void wxApp::MacHandleOneEvent( WXEVENTREF evr ) #if wxUSE_THREADS wxMutexGuiLeaveOrEnter(); #endif // wxUSE_THREADS + + CFArrayRemoveAllValues( GetAutoReleaseArray() ); +} + +void wxApp::MacAddToAutorelease( void* cfrefobj ) +{ + CFArrayAppendValue( GetAutoReleaseArray(), cfrefobj ); } long wxMacTranslateKey(unsigned char key, unsigned char code) -- 2.45.2