Hi folks,

I've got a section of code which crashes intermittently under 10.6 but despite being enclosed in try/catch blocks, my app is still forced to terminate. For what it's worth, all of the crash reports are from 10.6.x. My app seems to be rock solid when run under 10.4 and 10.5. In fact, for one user, the same version of my app only started crashing after he had upgraded to 10.6. It could be coincidental but I figured it was worth mentioning.

Anyway, the method (code below) loops through a mutable array of NSStrings. Each string acts as a key into two NSMutableDictionary objects (myItemList and imminentList).

If the key isn't found in either dictionary, it gets added to myItemList with an NSNumber value of -1. After I've examined all the keys, the mutable array is emptied so we don't see these particular items again the next time round the thread's runloop.

I've got everything apart from the NSLock logic surrounded in a try/ catch block, but when it goes wrong the catch block doesn't get executed and my app crashes.

I can't reproduce the problem myself (my main dev machine is still 10.5.8), but enough people have it that I know it's not an isolated incident.

The fact that it's crashing at CFBasicHashFindBucket implies some issue with the calls to objectForKey or setObject:ForKey, but does anyone know what could be causing it to crash so badly that my exception handler can't catch it?

Many thanks for your help,
Mark

PS. Yes, I know there are faster and more efficient ways to enumerate an array, but the old-school 'for' loop approach still comes to mind first and I still prefer it for small arrays.


Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000010
Crashed Thread:  3

Thread 3 Crashed:
0 com.apple.CoreFoundation 0x9079e7aa ___CFBasicHashFindBucket1 + 170 1 com.apple.CoreFoundation 0x907a6aac CFBasicHashFindBucket + 252
2   com.apple.CoreFoundation            0x907a6973 CFDictionaryGetValue + 131
3 ...allan.identifier 0x00009e06 -[Dispatcher copyItemsToMyItemListFrom:] + 577
4   ...allan.identifier                         0x000099b9 -[Dispatcher 
mainLoop:] + 223
5   com.apple.Foundation                0x940d58d8 -[NSThread main] + 45
6   com.apple.Foundation                0x940d5888 __NSThread__main__ + 1499
7   libSystem.B.dylib                   0x9435dfbd _pthread_start + 345
8   libSystem.B.dylib                   0x9435de42 thread_start + 34


- (void) copyItemsToMyItemListFrom: (NSMutableArray *) listToCopyFrom {
// we only need to lock the itemList as it's the only array whose contents may be changed by external threads. We don't really care if imminentList changes because the dictionary object will always be there even if the contents aren't.
        [self getLock4itemList];
        @try{
                [listToCopyFrom retain];
                int counter = 0;
                for (counter=0; counter < [listToCopyFrom count]; counter++) {
                        NSString *theKey = [listToCopyFrom 
objectAtIndex:counter];
                        if(theKey != nil){
if ( ([myItemList objectForKey:theKey] == nil) && ([imminentList objectForKey:theKey] == nil)) { [myItemList setObject:[NSNumber numberWithLongLong:-1] forKey:theKey];
                                }
                                else{
                                        //theKey already exists, don't add it 
again
                                }
                        }
                }
[listToCopyFrom removeAllObjects]; // remove all the objects so we don't see them again next time around [listToCopyFrom release]; // counteracts the retain at start of this method
        }
        @catch (NSException *e) {
                NSLog(@"Splat! Reason: %@", [e reason]);
        }
        [self releaseLock4itemList];
}

Thanks
Mark

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to