[futurebasic] Callback for CFArrayBSearchValues() operates differently in Lion vs. Snow Leopard

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2011 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Wed, 8 Jun 2011 12:52:33 -0700
My shareware app which runs fine in 10.5/10.6 crashes on launch ( stack trace below ) in Lion


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.apple.CoreFoundation      	0x9755ae07 ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___ + 7
1   libobjc.A.dylib               	0x99454e03 objc_exception_throw + 155
2   com.apple.CoreFoundation      	0x9755e520 -[NSObject doesNotRecognizeSelector:] + 256
3   com.apple.CoreFoundation      	0x974adbd9 ___forwarding___ + 457
4   com.apple.CoreFoundation      	0x974ad9a2 _CF_forwarding_prep_0 + 50
5   com.apple.CoreFoundation      	0x97417e22 CFDictionaryGetValue + 114
6   com.brianstevens.ccnx         	0x00008350 MySearchCallBack + 40 (_44_Sort_BSearch.incl.m:27)
7   com.apple.CoreFoundation      	0x97435e30 CFArrayBSearchValues + 64
8   com.brianstevens.ccnx         	0x0000831d BinarySearch + 67 (_44_Sort_BSearch.incl.m:58)
9   com.brianstevens.ccnx         	0x0001b581 DrawDaysOnScreen + 556 (_84_calendar.incl.m:342)
10  com.brianstevens.ccnx         	0x0001c049 ManageCalWindow + 46 (_84_calendar.incl.m:470)
11  com.brianstevens.ccnx         	0x00020795 DoInit + 457 (_90_initialize.incl.m:161)
12  com.brianstevens.ccnx         	0x00020c0d main + 946 (_91_CCN_X.m:101)
13  com.brianstevens.ccnx         	0x000026e5 start + 53

The cause of the crash is CFDictionaryGetValue() is given in invalid CFDictionaryRef. Further investigation in the debugger shows  CFArrayBSearchValues()’s  callback function receives parameters in a different order on Lion vs. Snow Leopard. The code below shows the essentials, although the call to fn BinarySearch has been pulled out of context and doesn’t show how is vars are defined. The key variables in the callback are val2 the CFDictionaryRef and date1 the CFDateRef. I did a "Print Description to Console" in both Lion and SL at the same point in the execution ( i.e. just before CFDictionaryGetValue() would execute in the callback ) and the screen prints below show how the values for the two variables are switched. 

Any suggestions for making this work or banging me over the head to point out an error are welcome. Looks to me like new behavior. I’m wondering if it is possible to conditionally compile two versions of the callback ( one for SL and one for Lion )

TIA----Brian

'--------
local fn MySearchCallBack( date1 as CFDateRef, val2 as CFDictionaryRef, context as pointer) as CFComparisonResult
'~'1
dim as CFComparisonResult   result    : result = _kCFCompareEqualTo
dim as long                 sortField : sortField = context
dim as CFDateRef            date2

date2  = fn CFDictionaryGetValue( val2, gDayNoteDateKey )
date2  = fn CFRetain( date2 )

select ( sortField )

case _kDateField

result = fn CFDateCompare( date1, date2, 0 ) 

case _kNoteDataField
end select
CFRelease( date2 )

end fn = result

// Binary search returns either an index where found or insertion index
// Caller must check returned index to find out if it is found or not
local fn BinarySearch( array as CFMutableArrayRef, searchVal as CFDateRef, cbFunction as pointer, context as pointer ) as CFIndex
'~'1
end fn = fn CFArrayBSearchValues( array, fn CFRangeMake( 0, fn CFArrayGetCount( array ) ), searchVal, cbFunction, context )

index      = fn BinarySearch( gDayNotesRemindersRef, searchDate, @fn MySearchCallBack, _kDateField  )
'--------

On Snow Leopard



On LION


Brian S







Attachments: