NSRangeException in saving dictionary?

Hello,


I'm seeing a crash bug that I do not understand. I have a large NSDictionary of data which I save using writeToFile:atomically.

Our crash monitoring shows this is generating a 'NSRangeException' crash for some players. The crash log is below.

I am saving the dictionary on a background thread, as it was blocking the main UI, so perhaps the crash is related to that?


NSDictionary* copyOfCatalog = [NSDictionary dictionaryWithDictionary:_libraryCatalog];

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),

^{

BOOL saveStatus = [copyOfCatalog writeToFile:pathToFile atomically:YES];

});


Fatal Exception: NSRangeException

*** -[__NSArrayM objectAtIndex:]: index 63 beyond bounds [0 .. 62]

0 CoreFoundation 0x18451ed8c __exceptionPreprocess

1 libobjc.A.dylib 0x1836d85ec objc_exception_throw

2 CoreFoundation 0x1844b7750 _CFArgv

3 CoreFoundation 0x1843e7810 -[__NSArrayM removeObjectAtIndex:]

4 CoreFoundation 0x1843f1a40 _CFAppendXML0

5 CoreFoundation 0x1843f21b8 _CFAppendXML0

6 CoreFoundation 0x1843f21b8 _CFAppendXML0

7 CoreFoundation 0x1843f1118 _CFPropertyListCreateXMLData

8 CoreFoundation 0x1843fcb94 CFPropertyListCreateData

9 Foundation 0x184e8bcf4 +[NSPropertyListSerialization dataWithPropertyList:format:options:error:]

10 Foundation 0x184ecd1bc -[NSDictionary(NSDictionary) writeToFile:atomically:]

11 DemoApp 0x10062ce08 __32-[LibraryManager saveCatalog]_block_invoke (LibraryManager.m:578)


This is seen on iOS 11.4 and iOS 11.3.1 and others.


Any suggestions on where to look would be appreciated.


Thanks!

Is this code part of savecatalog func ?


NSDictionary* copyOfCatalog   = [NSDictionary dictionaryWithDictionary:_libraryCatalog];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
                ^{
                 BOOL saveStatus = [copyOfCatalog writeToFile:pathToFile atomically:YES];
                });


What is the var that has 63 elements ?

You are trying to access beyong the array limit:

[__NSArrayM objectAtIndex:]: index 63 beyond bounds [0 .. 62]


You should show more code si that we can understand the context.

NSRangeException in saving dictionary?
 
 
Q