Xcode 4 bug: Crash when using Core Data Model from Xcode 3

0.00 avg. rating (0% score) - 0 votes

I recently upgraded my Xcode from version 3 to 4.0.2 (build 4A2002a) and notice that Xcode keeps on crashing whenever I right click on a core data model used in an iOS application:

The error message reads:

Xcode encountered an internal logic error. Choose "Continue" to continue running Xcode in an inconsistent state.  Choose "Crash" to halt Xcode and file a bug with Crash Reporter. Choosing "Crash" will result in the loss of all unsaved data.

ASSERTION FAILURE in /SourceCache/IDEKit/IDEKit-303/Framework/Classes/StructureEditingAdditions/IDEStructureEditing+Additions.m:587
Details:  Assertion failed: [indexes lastIndex] <= [_targetGroup.subitems count]
Object:  
Method:   -structureEditingCanGroupSubitemsAtIndexes:
Thread:   {name = (null), num = 1}
Hints:   None
Backtrace:
  0  0x0000000100949773 -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
  1  0x000000010006d394 _DVTAssertionFailureHandler (in DVTFoundation)
  2  0x00000001009a683e -[IDEContainerItemStructureEditingTarget structureEditingCanGroupSubitemsAtIndexes:] (in IDEKit)
  3  0x000000011e9e5661 -[IDEStructureNavigator _testOrGroupSelected:useContextualMenuSelection:] (in IDEStructureNavigator)
  4  0x000000011e9e2617 -[IDEStructureNavigator validateUserInterfaceItem:] (in IDEStructureNavigator)
  5  0x00007fff834a538b -[NSMenu _enableItem:] (in AppKit)
  6  0x00007fff834a50e8 -[NSCarbonMenuImpl _carbonUpdateStatusEvent:handlerCallRef:] (in AppKit)
  7  0x00007fff8348899c NSSLMMenuEventHandler (in AppKit)
  8  0x00007fff884357f7 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) (in HIToolbox)
  9  0x00007fff88434d46 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) (in HIToolbox)
 10  0x00007fff88452a81 SendEventToEventTarget (in HIToolbox)
 11  0x00007fff88481c35 SendHICommandEvent(unsigned int, HICommand const*, unsigned int, unsigned int, unsigned char, void const*, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) (in HIToolbox)
 12  0x00007fff8849510f UpdateHICommandStatusWithCachedEvent (in HIToolbox)
 13  0x00007fff88431725 HIApplication::EventHandler(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) (in HIToolbox)
 14  0x00007fff884357f7 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) (in HIToolbox)
 15  0x00007fff88434d46 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) (in HIToolbox)
 16  0x00007fff88452a81 SendEventToEventTarget (in HIToolbox)
 17  0x00007fff8849476f SendMenuOpening(MenuSelectData*, MenuData*, double, unsigned int, __CFDictionary*, unsigned char, unsigned char*) (in HIToolbox)
 18  0x00007fff885b77ae PopUpMenuSelectCore(MenuData*, Point, double, Point, unsigned short, unsigned int, Rect const*, unsigned short, unsigned int, Rect const*, Rect const*, __CFString const*, OpaqueMenuRef**, unsigned short*) (in HIToolbox)
 19  0x00007fff885b7dc2 _HandlePopUpMenuSelection7 (in HIToolbox)
 20  0x00007fff835da99b _NSSLMPopUpCarbonMenu3 (in AppKit)
 21  0x00007fff835dad4b -[NSCarbonMenuImpl _popUpContextMenu:withEvent:forView:withFont:] (in AppKit)
 22  0x00007fff8372bb37 -[NSMenu _popUpContextMenu:withEvent:forView:withFont:] (in AppKit)
 23  0x00007fff836304c0 -[NSControl _rightMouseUpOrDown:] (in AppKit)
 24  0x00007fff834270c7 -[NSWindow sendEvent:] (in AppKit)
 25  0x00007fff8335bafa -[NSApplication sendEvent:] (in AppKit)
 26  0x000000010085b36e -[IDEApplication sendEvent:] (in IDEKit)
 27  0x00007fff832f26de -[NSApplication run] (in AppKit)
 28  0x00007fff832eb3b0 NSApplicationMain (in AppKit)
 29  0x0000000100000eec

I may click ‘Continue’ on the dialog box to ignore the error, but subsequently Xcode would just crash randomly and too unstable to be used. For example, clicking on the Help menu would crash Xcode, but not any other menu.

The root cause, after much investigation, was the hierarchy of the .h and .m files for the core data class objects. In my original project from Xcode 3, the .h and .m files stayed under the .xcdatamodeld file in the project tree:

This was the default behavior on Xcode 3. However, Xcode 4 does not allow you to place these files under the .xcdatamodeld file, which is perhaps why it crashed since the case was never handled. I removed all the .h and .m files, regenerated them and put them under the CoreData group, and Xcode stopped crashing (for now):

I thought that was it, but unfortunately the problem did not stop there. Xcode again crashed when I attempted to commit the project to SVN:

The reason for the crash was ‘editorDocument should be an instance inheriting from IDE-QuickLookdocument, but…’ Perhaps only Apple knows what this really means… Nothing really helped, including restarting Xcode, closing all open source code files or cleaning/rebuilding the project. In the end, I committed to SVN from command line, checked out a fresh copy of the project and Xcode no longer crashed when committing!

Finally, I am somewhat disappointed at Xcode 4.0.2. The UI changed significantly and some of the important behavior also changed, perhaps without any documentation at all! For example, for each core data relationship, the Edit>Create NSManagedObject subclass… creates the methods to add/delete objects to the relationship in the .m file, but forgets to to put them in the header file. This results in plenty of compilation warnings if your code is from Xcode 3 and the core data class files are regenerated using Xcode 4. I have to resort to manually modifying the header files to add the correct method signatures…

I hope these issues will soon be fixed in the next release of Xcode.

0.00 avg. rating (0% score) - 0 votes
ToughDev

ToughDev

A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>