Prevent UIDocumentInteractionController PresentPreview from crashing my App - iphone

I'm trying to preview a file with UIDocumentInteractionController. Seems simple enough but randomly the app crashes with a SIGSEGV, and after a few hours trying all kind of hacks I just don't get what's missing.
This code is called from my UIViewController class :
void Initialize ()
{
mInteractionControllerDelegate = new UIDocumentInteractionControllerDelegateClass(this, mFile);
mInteractionController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(mFile.Name));
mInteractionController.Delegate = mInteractionControllerDelegate;
}
mInteractionControllerDelegate and mInteractionController are member variables of my view controller class (I tried that, in order to make sure an event wasn't firing on a variable that would have been GCed)
I present the preview on a button click (the part with the MPMoviePlayerViewController is working fine :
void btnShowTouchUpInside (object sender, EventArgs e)
{
if (mFile.Name.EndsWith(".mpeg") || mFile.Name.EndsWith(".avi") || mFile.Name.EndsWith(".mpg"))
{
MPMoviePlayerViewController mp = new MPMoviePlayerViewController(NSUrl.FromString(mFile.VideoURL));
this.PresentMoviePlayerViewController(mp);
}
else
{
InvokeOnMainThread(delegate {
mInteractionController.PresentPreview(true);
});;
}
}
In some cases, the preview will work (small txt files for example : but I'm not sure of the file size => crash correlation). But if I try with some bigger png files for example (500 ko), I see the preview for a few seconds, and then then app crashes with the following stack trace :
Stacktrace:
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) <IL 0x00024, 0xffffffff>
at MonoTouch.Foundation.NSObject/MonoTouch_Disposer.Drain (MonoTouch.Foundation.NSObject) [0x0002a] in /Users/plasma/Source/iphone/monotouch/Foundation/NSObject.cs:305
at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <IL 0x00052, 0xffffffff>
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26
at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:31
at DTS.Application.Main (string[]) [0x00000] in /Users/seb/Projects/DTS/DTS/Main.cs:14
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
0 DTS 0x000d1965 mono_handle_native_sigsegv + 343
1 DTS 0x0000ffb4 mono_sigsegv_signal_handler + 322
2 libSystem.B.dylib 0x98a9f45b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 ??? 0x0d24837c 0x0 + 220496764
5 ??? 0x077520d6 0x0 + 125116630
6 DTS 0x0000fd6f mono_jit_runtime_invoke + 1332
7 DTS 0x001ee239 mono_runtime_invoke + 137
8 DTS 0x0029e9ab monotouch_trampoline + 2527
9 Foundation 0x0140e94e __NSThreadPerformPerform + 251
10 CoreFoundation 0x00ea08ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
11 CoreFoundation 0x00dfe88b __CFRunLoopDoSources0 + 571
12 CoreFoundation 0x00dfdd86 __CFRunLoopRun + 470
13 CoreFoundation 0x00dfd840 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x00dfd761 CFRunLoopRunInMode + 97
15 GraphicsServices 0x0404c1c4 GSEventRunModal + 217
16 GraphicsServices 0x0404c289 GSEventRun + 115
17 UIKit 0x01ce0c93 UIApplicationMain + 1160
18 ??? 0x09d540a3 0x0 + 164970659
19 ??? 0x09d53e74 0x0 + 164970100
20 ??? 0x09d53474 0x0 + 164967540
21 ??? 0x09d532cc 0x0 + 164967116
22 ??? 0x09d5341e 0x0 + 164967454
23 DTS 0x0000fd6f mono_jit_runtime_invoke + 1332
24 DTS 0x001ee239 mono_runtime_invoke + 137
25 DTS 0x001f0920 mono_runtime_exec_main + 669
26 DTS 0x001efd0a mono_runtime_run_main + 843
27 DTS 0x000a3c62 mono_jit_exec + 200
28 DTS 0x002a25eb main + 3838
29 DTS 0x000030c9 _start + 208
30 DTS 0x00002ff8 start + 40
Debug info from gdb:
/tmp/mono-gdb-commands.VWK7bK:1: Error in sourced command file:
unable to debug self
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Final clue : this is the code for the UIDocumentInteractionControllerDelegateClass (created from other questions on SO) :
public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate
{
private UIViewController mViewController;
private DTSVirtualFile mFile;
public UIDocumentInteractionControllerDelegateClass(UIViewController viewController, DTSVirtualFile file)
{
mViewController = viewController;
mFile = file;
}
public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
{
return mViewController;
}
public override UIView ViewForPreview (UIDocumentInteractionController controller)
{
return mViewController.View;
}
public override RectangleF RectangleForPreview (UIDocumentInteractionController controller)
{
return mViewController.View.Frame;
}
public override void DidEndPreview (UIDocumentInteractionController controller)
{
mFile.DeleteCopy();
}
public override void DidDismissOptionsMenu (UIDocumentInteractionController controller)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
public override void WillBeginPreview (UIDocumentInteractionController controller)
{
Console.WriteLine("WillBeginPreview");
}
public override void WillBeginSendingToApplication (UIDocumentInteractionController controller)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
public override void WillPresentOpenInMenu (UIDocumentInteractionController controller)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
public override void WillPresentOptionsMenu (UIDocumentInteractionController controller)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
}
When I debug I can step over PresentPreview fine, but it then crashes right afterwards. If I comment the PresentPreview line, no crash.
Any pointers, solutions ?

There's an ABI bug that affects MonoTouch when methods returns structs (not classes), like a RectangleF and leads to similar crashes. Device builds (using a different ABO) are not affected by this issue.
A workaround is to avoid overriding methods that returns structure such as:
public override RectangleF RectangleForPreview (UIDocumentInteractionController controller)

Related

Implement document drag to application in macOS using swift

I am trying to associate a certain filename extension with my macOS application, which I have managed to do by following this guide and can drag my file in to my application.
When I drag my file in, I get this exception in the console:
2017-11-06 09:56:23.944202+0000 Test App[64192:2356795] [General] readFromData:ofType:error: is a subclass responsibility but has not been overridden.
2017-11-06 09:56:23.958166+0000 Test App[64192:2356795] [General] (
0 CoreFoundation 0x00007fff45f560fb exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff6c844c76 objc_exception_throw + 48
2 CoreFoundation 0x00007fff45fe7bfd +[NSException raise:format:] + 205
3 AppKit 0x00007fff43a0b860 -[NSDocument readFromData:ofType:error:] + 253
4 AppKit 0x00007fff43a0b544 -[NSDocument readFromURL:ofType:error:] + 620
5 AppKit 0x00007fff436eb9b9 -[NSDocument _initWithContentsOfURL:ofType:error:] + 172
6 AppKit 0x00007fff436eb89e -[NSDocument initWithContentsOfURL:ofType:error:] + 231
7 AppKit 0x00007fff437c12dd -[NSDocumentController makeDocumentWithContentsOfURL:ofType:error:] + 628
8 AppKit 0x00007fff43a42578 __97-[NSDocumentController makeDocumentWithContentsOfURL:alternateContents:ofType:completionHandler:]_block_invoke + 91
9 AppKit 0x00007fff43a42512 -[NSDocumentController makeDocumentWithContentsOfURL:alternateContents:ofType:completionHandler:] + 176
10 AppKit 0x00007fff437c0493 __80-[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:]_block_invoke + 880
11 AppKit 0x00007fff43a411b9 __144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke_4 + 31
12 AppKit 0x00007fff43a41542 __144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke_2.970 + 149
13 AppKit 0x00007fff43a4147d __144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke.969 + 138
14 AppKit 0x00007fff43a4133f __144-[NSDocumentController _coordinateReadingAndGetAlternateContentsForOpeningDocumentAtURL:resolvingSymlinks:thenContinueOnMainThreadWithAccessor:]_block_invoke.964 + 254
15 CoreFoundation 0x00007fff45eee52c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
16 CoreFoundation 0x00007fff45ed0f43 __CFRunLoopDoBlocks + 275
17 CoreFoundation 0x00007fff45ed0d08 __CFRunLoopRun + 3128
18 CoreFoundation 0x00007fff45ecfe43 CFRunLoopRunSpecific + 483
19 HIToolbox 0x00007fff451ef866 RunCurrentEventLoopInMode + 286
20 HIToolbox 0x00007fff451ef5d6 ReceiveNextEventCommon + 613
21 HIToolbox 0x00007fff451ef354 _BlockUntilNextEventMatchingListInModeWithFilter + 64
22 AppKit 0x00007fff434ec9f7 _DPSNextEvent + 2085
23 AppKit 0x00007fff43c81d98 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
24 AppKit 0x00007fff434e1805 -[NSApplication run] + 764
25 AppKit 0x00007fff434b09a6 NSApplicationMain + 804
26 Test App 0x000000010004cd1d main + 13
27 libdyld.dylib 0x00007fff6d433145 start + 1
28 ??? 0x0000000000000003 0x0 + 3
I've tried implementing the NSApplicationDelegate openFile functions but none of them are called when I drag the file on to the app:
#NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func application(_ application: NSApplication, open urls: [URL]) {
}
func application(_ sender: NSApplication, openFile filename: String) -> Bool {
return false
}
func application(_ sender: NSApplication, openFiles filenames: [String]) {
}
func application(_ sender: NSApplication, openTempFile filename: String) -> Bool {
return false
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
How do I get access to the filename and contents of the "dragged in" file? I am using XCode 9.0.1 and Swift 4.
Edit:
Here is my Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>tal</string>
</array>
<key>CFBundleTypeIconFile</key>
<string></string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string></string>
</array>
<key>CFBundleTypeName</key>
<string>Layout File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.testapp.layout</string>
</array>
<key>LSTypeIsPackage</key>
<integer>0</integer>
<key>NSDocumentClass</key>
<string>NSDocument</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>v1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string></string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.video</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>Layout File</string>
<key>UTTypeIconFile</key>
<string></string>
<key>UTTypeIdentifier</key>
<string>com.testapp.layout</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>tal</string>
</array>
</dict>
</dict>
<dict/>
</array>
</dict>
</plist>
So I would have expected application(_ sender: NSApplication, openFile filename: String) to be called when I drag the file on to the app when it's in the Dock...
There are a number of points here to address:
if you're working in macOS 10.12 or below, you should implement either openFile or openFiles. openURLs is 10.13+ - but you definitely don't need both
openFile will be called for each of multiple files; if openFiles is present, openFile will not be called, even if you open only a single file
I have no idea what openTempFile (or openUntitledFile) are about; I haven't been able to get anyone to call either
openFile(s) get called when you have successfully registered a UTI with the system; double-clicking an appropriate file(s) in the Finder, choosing 'open' or dragging the file onto the dock icon of your app all send an open message that gets handled by the AppDelegate.
I am not clear what you mean by 'When I drag my file in': if you drag your file onto the app icon in the Finder, openFile(s) should be called; your wording makes me think that your drag destination is part of your application's interface, in which case you need to handle dragging yourself.
Also check - because the linked (iOS) guide does not address this - that you have set your NSDocument class: your example says 'NSDocument', but there is an extreme likelihood that your application uses a custom subclass; so you need to set the 'Class' to that name.

jxbrowser on macosx using SWT deadlock

I have finished evaluating jxbrowser integration with Eclipse for Windows and Linux. My last roadblock is Mac. I get a dead lock while instantiating the browser. I am new to cocoa programming, so any pointer will be greatly appreciated.
I took the example project and modify it to work with SWT.
import java.awt.BorderLayout;
import java.awt.Frame;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
public class JxBrowserApp {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
Composite composite = new Composite(shell, SWT.EMBEDDED | SWT.NO_BACKGROUND);
Frame frame = SWT_AWT.new_Frame(composite);
Browser browser = new Browser(); // deadlock here
BrowserView browserView = new BrowserView(browser);
frame.add(browserView, BorderLayout.CENTER);
frame.setLocationRelativeTo(null);
frame.setFocusable(true);
browser.loadURL("http://www.google.com");
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Here is the callstack
JxBrowserApp at localhost:57970
Thread [main] (Suspended)
owns: IPC (id=72)
Unsafe.park(boolean, long) line: not available [native method]
LockSupport.parkNanos(Object, long) line: 215
CountDownLatch$Sync(AbstractQueuedSynchronizer).doAcquireSharedNanos(int, long) line: 1037
CountDownLatch$Sync(AbstractQueuedSynchronizer).tryAcquireSharedNanos(int, long) line: 1328
CountDownLatch.await(long, TimeUnit) line: 277
LatchUtil.await(CountDownLatch, RuntimeException, int) line: 25
LatchUtil.await(CountDownLatch, RuntimeException) line: 20
IPC.a(boolean) line: 159
IPC.start() line: 128
Browser.<init>(BrowserType, BrowserContext, Channel) line: 195
Browser.<init>(BrowserType, BrowserContext) line: 172
Browser.<init>(BrowserContext) line: 139
Browser.<init>() line: 125
JxBrowserApp.main(String[]) line: 27
Thread [AWT-EventQueue-0] (Suspended)
CPlatformView.nativeCreateView(int, int, int, int, long) line: not available [native method]
CPlatformView.initialize(LWWindowPeer, CPlatformResponder) line: 61
CViewPlatformEmbeddedFrame.initialize(Window, LWWindowPeer, PlatformWindow) line: 55
LWWindowPeer.<init>(Window, PlatformComponent, PlatformWindow, LWWindowPeer$PeerType) line: 156
LWCToolkit(LWToolkit).createDelegatedPeer(Window, PlatformComponent, PlatformWindow, LWWindowPeer$PeerType) line: 210
LWCToolkit.createEmbeddedFrame(CViewEmbeddedFrame) line: 204
CViewEmbeddedFrame.addNotify() line: 55
SWT_AWT$1.run() line: not available
InvocationEvent.dispatch() line: 311
EventQueue.dispatchEventImpl(AWTEvent, Object) line: 756
EventQueue.access$500(EventQueue, AWTEvent, Object) line: 97
EventQueue$3.run() line: 709
EventQueue$3.run() line: 703
AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: 76
EventQueue.dispatchEvent(AWTEvent) line: 726
EventDispatchThread.pumpOneEventForFilters(int) line: 201
EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 116
EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 105
EventDispatchThread.pumpEvents(int, Conditional) line: 101
EventDispatchThread.pumpEvents(Conditional) line: 93
EventDispatchThread.run() line: 82
Daemon Thread [Timer-0] (Suspended)
waiting for: TaskQueue (id=87)
Object.wait(long) line: not available [native method]
TimerThread.mainLoop() line: 552
TimerThread.run() line: 505
Daemon Thread [IPC Server Thread] (Suspended)
PlainSocketImpl.socketAccept(SocketImpl) line: not available [native method]
SocksSocketImpl(AbstractPlainSocketImpl).accept(SocketImpl) line: 409
ServerSocket.implAccept(Socket) line: 545
ServerSocket.accept() line: 513
Server.start(int) line: 81
e.run() line: 1237
Thread.run() line: 745
Daemon Thread [IPC Process Thread] (Suspended)
CGraphicsDevice.nativeGetScreenInsets(int) line: not available [native method]
CGraphicsDevice.getScreenInsets() line: 128
LWCToolkit.getScreenInsets(GraphicsConfiguration) line: 407
SwingUtilities$SharedOwnerFrame(Window).init(GraphicsConfiguration) line: 506
SwingUtilities$SharedOwnerFrame(Window).<init>() line: 537
SwingUtilities$SharedOwnerFrame(Frame).<init>(String) line: 420
SwingUtilities$SharedOwnerFrame(Frame).<init>() line: 385
SwingUtilities$SharedOwnerFrame.<init>() line: 1758
SwingUtilities.getSharedOwnerFrame() line: 1833
JWindow.<init>(Frame) line: 187
JWindow.<init>() line: 139
InternalChromiumProcess.doStart(List<String>) line: 1078
InternalChromiumProcess(ChromiumProcess).start(int) line: 123
d.run() line: 184
Thread.run() line: 745

Deadlock between a dispatch_sync on the main queue and executeFetchRequest:error:

I am dispatch_sync()'ing a block on the main queue. In this block, a call to executeFetchRequest:error: is eventually made. Sometimes, this causes a deadlock.
Here is Thread 1 which shows the block invoked on the main thread and then the call to executeFetchRequest:error:
#0 0x981f3876 in __psynch_mutexwait ()
#1 0x97a016af in pthread_mutex_lock ()
#2 0x0135be32 in -[_PFLock lock] ()
#3 0x0135be0a in -[NSPersistentStoreCoordinator lock] ()
#4 0x01371d1c in -[NSManagedObjectContext(_NSInternalAdditions) lockObjectStore] ()
#5 0x013702c0 in -[NSManagedObjectContext executeFetchRequest:error:] ()
#6 0x0000a701 in -[NSManagedObjectContext(Convenience) fetchObjectsForEntityName:onlyIDs:withPredicate:] at /Users/mike/Dropbox/src/Tracky-iPhone/Tracky/Tracky/NSManagedObjectContext(Convenience).m:50
#7 0x00065270 in +[NSManagedObject(ContextAdditions) contextForID:managedObjectContext:] at /Users/mike/Dropbox/src/Tracky-iPhone/Tracky/Tracky/NSManagedObject+ContextAdditions.m:40
#8 0x0006597e in __85+[NSManagedObject(ContextAdditions) createContextIfNeededForID:managedObjectContext:]_block_invoke_0 at /Users/mike/Dropbox/src/Tracky-iPhone/Tracky/Tracky/NSManagedObject+ContextAdditions.m:55
#9 0x00065aad in __85+[NSManagedObject(ContextAdditions) createContextIfNeededForID:managedObjectContext:]_block_invoke_050 at /Users/mike/Dropbox/src/Tracky-iPhone/Tracky/Tracky/NSManagedObject+ContextAdditions.m:64
#10 0x023cf8d9 in _dispatch_barrier_sync_f_slow_invoke ()
#11 0x023d0509 in _dispatch_main_queue_callback_4CF ()
#12 0x01ae9803 in __CFRunLoopRun ()
#13 0x01ae8d84 in CFRunLoopRunSpecific ()
#14 0x01ae8c9b in CFRunLoopRunInMode ()
#15 0x019b47d8 in GSEventRunModal ()
#16 0x019b488a in GSEventRun ()
#17 0x004ba626 in UIApplicationMain ()
I can see that executeFetchRequest:error: is blocking on NSPersistentStoreCoordinator's lock, but I don't know who currently has it locked.
The original dispatch_sync() is occurring from a different thread, and here's that in case it's important:
Thread 18, Queue : (null)
#0 0x981f1c5e in semaphore_wait_trap ()
#1 0x023d1bda in _dispatch_thread_semaphore_wait ()
#2 0x023d0cb2 in _dispatch_barrier_sync_f_slow ()
#3 0x023d0e0f in dispatch_barrier_sync_f ()
#4 0x023d0f4c in _dispatch_sync_slow ()
#5 0x0006563a in +[NSManagedObject(ContextAdditions) createContextIfNeededForID:managedObjectContext:] at /Users/mike/Dropbox/src/Tracky-iPhone/Tracky/Tracky/NSManagedObject+ContextAdditions.m:63
#6 0x0006e2ee in __109-[ItemFetcher createOrConfigureObjectWithDescriptor:withContext:jsonObjectIDKey:modelObjectIDKey:entityName:]_block_invoke_0 at /Users/mike/Dropbox/src/Tracky-iPhone/Tracky/Tracky/ItemFetcher.m:78
#7 0x023ce330 in _dispatch_call_block_and_release ()
#8 0x023cff0c in _dispatch_queue_drain ()
#9 0x023cfcb4 in _dispatch_queue_invoke ()
#10 0x023cf402 in _dispatch_worker_thread2 ()
#11 0x97a04b24 in _pthread_wqthread ()
Here is the code up to the original dispatch:
+ (Context *) createContextIfNeededForID: (NSString *) contextID managedObjectContext:(NSManagedObjectContext *) moc
{
// See if this context is in the main MOC. This call needs to happen synchronously on the main queue, if we're
// not on the main queue
Context * (^contextFromMainMOCBlock)(void) =
^ `Context` * {
// We are guaranteed to be in the main here; look at how this block is invoked.
return [self contextForID:contextID managedObjectContext:[UIApplication trackyAppDelegate].managedObjectContext] ;
} ;
__block Context *contextFromMainMOC = nil ;
if( [UIApplication trackyAppDelegate].managedObjectContext == moc )
contextFromMainMOC = contextFromMainMOCBlock() ;
else
dispatch_sync(dispatch_get_main_queue(), ^{
contextFromMainMOC = contextFromMainMOCBlock() ; // <-- here
}) ;
…
contextForID:contextID managedObjectContext: really doesn't do anything with core data until it calls executeFetchRequest:error:.
UPDATE
Here are the rest of the stack traces. AFAIK they're not doing anything interesting although I may be wrong.
Thread 3, Queue : (null)
#0 0x981f490a in kevent ()
#1 0x023d0372 in _dispatch_mgr_invoke ()
#2 0x023cebe1 in _dispatch_mgr_thread ()
Thread 5 WebThread, Queue : (null)
#0 0x981f1c22 in mach_msg_trap ()
#1 0x981f11f6 in mach_msg ()
#2 0x01b8610a in __CFRunLoopServiceMachPort ()
#3 0x01ae95d5 in __CFRunLoopRun ()
#4 0x01ae8d84 in CFRunLoopRunSpecific ()
#5 0x01ae8c9b in CFRunLoopRunInMode ()
#6 0x04776420 in _ZL12RunWebThreadPv ()
#7 0x97a02ed9 in _pthread_start ()
Thread 6 com.apple.NSURLConnectionLoader, Queue : (null)
#0 0x981f1c22 in mach_msg_trap ()
#1 0x981f11f6 in mach_msg ()
#2 0x01b8610a in __CFRunLoopServiceMachPort ()
#3 0x01ae95d5 in __CFRunLoopRun ()
#4 0x01ae8d84 in CFRunLoopRunSpecific ()
#5 0x01ae8c9b in CFRunLoopRunInMode ()
#6 0x00ebae30 in +[NSURLConnection(Loader) _resourceLoadLoop:] ()
#7 0x00dcc4d6 in -[NSThread main] ()
#8 0x00dcc447 in __NSThread__main__ ()
#9 0x97a02ed9 in _pthread_start ()
Thread 10 com.apple.CFSocket.private, Queue : (null)
#0 0x981f3b42 in select$DARWIN_EXTSN ()
#1 0x01b1a7cb in __CFSocketManager ()
#2 0x97a02ed9 in _pthread_start ()
And here is contextID:managedObjectContext: which is the method called in the dispatch_sync() :
+ (Context *) contextForID: (NSString *) contextID managedObjectContext:(NSManagedObjectContext *) moc
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"cid == %#", contextID] ;
NSSet *contexts = [moc fetchObjectsForEntityName:#"Context" onlyIDs:NO withPredicate:predicate] ;
// Integrity check
NSAssert1(contexts.count < 2, #"More than one context with the same CID exists: %#" , contexts) ;
return [contexts anyObject] ;
}
fetchObjectsForEntityName:onlyIDs:withPredicate: looks like this:
- (NSSet *)fetchObjectsForEntityName:(NSString *)newEntityName onlyIDs: (BOOL) onlyIDs
withPredicate:(id)stringOrPredicate, ...
{
NSEntityDescription *entity = [NSEntityDescription
entityForName:newEntityName inManagedObjectContext:self];
NSAssert1( entity != nil , #"entity not found for \"%#\"" , newEntityName ) ;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setIncludesPropertyValues:!onlyIDs] ;
if (stringOrPredicate)
{
NSPredicate *predicate;
if ([stringOrPredicate isKindOfClass:[NSString class]])
{
va_list variadicArguments;
va_start(variadicArguments, stringOrPredicate);
predicate = [NSPredicate predicateWithFormat:stringOrPredicate
arguments:variadicArguments];
va_end(variadicArguments);
}
else
{
NSAssert2([stringOrPredicate isKindOfClass:[NSPredicate class]],
#"Second parameter passed to %s is of unexpected class %#",
sel_getName(_cmd), NSStringFromClass(stringOrPredicate));
predicate = (NSPredicate *)stringOrPredicate;
}
[request setPredicate:predicate];
}
NSError *error = nil;
NSArray *results ;
#try {
results = [self executeFetchRequest:request error:&error];
}
#catch (NSException *exception) {
NSLog(#"Exception caught: %#" , exception) ;
}
if (error != nil)
{
[NSException raise:NSGenericException format:#"%#",[error description]];
}
return [NSSet setWithArray:results];
}
To give more help, you need to show the code for all methods in the stack traces, along with line numbers. That way, it can be correlated.
Also, it looks like you have a lot of threads. I think you are going to have to examine the others to see what is happening.
You have to be very careful when calling a sync operation, especially if it may be called from other sync operations.
Check your NSManagedObjectContext for concurrencyType. It seems that your context has NSMainQueueConcurrencyType, which runs all requests in the main thread. From Apple reference:
NSMainQueueConcurrencyType
Specifies that the context will be associated with the main queue.
If I'm right you need to change type to NSPrivateQueueConcurrencyType

sharedlibrary apply-load-rules all Warning: the current language does not match this frame. Current language: auto; currently objective-c

I have Integrated Cocos2d to my Windows based application. When I run my Project I am getting the Crash after executing the line CC_DIRECTOR_INIT(); The error is **sharedlibrary **apply-load-rules all
Warning: the current language does not match this frame.
Current language: auto; currently objective-c****. I found the meaning of the error form this POST. But My question is how can I Implement this in my Project. I am new to cocos2-d. Any suggestions is appreciated.
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
CC_DIRECTOR_INIT();
CCDirector *director = [CCDirector sharedDirector];
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[director setDisplayFPS:YES];
EAGLView *view = [director openGLView];
[view setMultipleTouchEnabled:YES];
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene: [Helloworld scene]];
}
This is the Screenshot where the crash occurs...
EDIT:
MY Console output..
#0 0x0002e60f in -[CCLabelAtlas updateAtlasValues] (self=0x68224c0, _cmd=0xc0be2) at CCLabelAtlas.m:75
#1 0x0002e994 in -[CCLabelAtlas setString:] (self=0x68224c0, _cmd=0x310f12c, newString=0xf3b98) at CCLabelAtlas.m:113
#2 0x0002e49c in -[CCLabelAtlas initWithString:charMapFile:itemWidth:itemHeight:startCharMap:] (self=0x68224c0, _cmd=0xb8d31, theString=0xf3b98, charmapfile=0xf3b88, w=16, h=24, c=46 '.') at CCLabelAtlas.m:50
#3 0x0002e380 in +[CCLabelAtlas labelAtlasWithString:charMapFile:itemWidth:itemHeight:startCharMap:] (self=0xf1ebc, _cmd=0xb6fd5, string=0xf3b98, charmapfile=0xf3b88, w=16, h=24, c=46 '.') at CCLabelAtlas.m:40
#4 0x0001268a in -[CCDirector setGLDefaultValues] (self=0x681c300, _cmd=0xb6b3d) at CCDirector.m:219
#5 0x0001406d in -[CCDirector setOpenGLView:] (self=0x681c300, _cmd=0xb6a18, view=0x681c850) at CCDirector.m:549
#6 0x00002e58 in -[cocowindowAppDelegate applicationDidFinishLaunching:] (self=0x681abe0, _cmd=0xd050a3, application=0x68016f0) at cocowindowAppDelegate.m:32
#7 0x00912ce2 in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] ()
#8 0x00914d88 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] ()
#9 0x0091f617 in -[UIApplication handleEvent:withNewEvent:] ()
#10 0x00917abf in -[UIApplication sendEvent:] ()
#11 0x0091cf2e in _UIApplicationHandleEvent ()
#12 0x02e61992 in PurpleEventCallback ()
#13 0x01403944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#14 0x01363cf7 in __CFRunLoopDoSource1 ()
#15 0x01360f83 in __CFRunLoopRun ()
#16 0x01360840 in CFRunLoopRunSpecific ()
#17 0x01360761 in CFRunLoopRunInMode ()
#18 0x009147d2 in -[UIApplication _run] ()
#19 0x00920c93 in UIApplicationMain ()
#20 0x00002b39 in main (argc=1, argv=0xbfffeff0) at main.m:14
(gdb)
EXC_ARITHMETIC usually means that you are dividing by zero. If you look in your screenshot then you are evaluating:
int row = (a % itemsPerRow) //...
From the output of your debugger it looks like itemsPerRow is 0 when this is caused and so the program is crashing. Try initialising this value or setting some conditional code if it is meant to be zero to stop it dividing by zero.
The warning message Warning: the current language does not match this frame. is just GDB getting a bit confused as to what language it is meant to be debugging. As you can see, it manages to sort itself out on the next line.
Edit:
This poster has a similar error to you: http://www.cocos2d-iphone.org/forum/topic/8209 Does his fix apply to you?

iphone core data deletion causes a crash

I have a core-data object "entity" with 2 fields - "name" (a NSString *) and "type" (a EntityType). EntityType is another core data obect with 1 field - name (NSString *).
I am creating and deleting an entity object using the code similar in functionality to the following code -
Entity *e1 = [NSEntityDescription insertNewObjectForEntityName:"#Entity" inManagedObjectContext: context]
EntityType *type = [NSEntityDescription insertNewObjectForEntityName:"#EntityType" inManagedObjectContext: context]
e1.type = type;
Now I delete the entity object without assigning any values or saving to the persistent store.
if([e1.name length] == 0) {
[context deleteObject:e1];
NSError *nil;
if(![context:save &error] {
// log error
}
}
At this point I see a crash, when I try to delete and save the object.
(Terminating due to uncaught exception 'NSRangeException' reason: [NSCFArray removeObjectAtIndex]: index(0) beyond bounds (0)]
Any pointers/suggestions are much appreciated.
Here's the stack trace that was requested -
#0 0x3266bdf4 in objc_exception_throw ()
#1 0x32d73b32 in +[NSException raise:format:arguments:] ()
#2 0x32d73ad2 in +[NSException raise:format:] ()
#3 0x33f4a710 in _NSArrayRaiseBoundException ()
#4 0x33f7ba3c in -[NSCFArray removeObjectAtIndex:] ()
#5 0x30537dc6 in -[NSFetchedResultsController(PrivateMethods) _removeObjectInFetchedObjectsAtIndex:] ()
#6 0x3053b50a in -[NSFetchedResultsController(PrivateMethods) _postprocessDeletedObjects:] ()
#7 0x3053aa9a in -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] ()
#8 0x33f765d8 in _nsnote_callback ()
#9 0x32d9e510 in _CFXNotificationPostNotification ()
#10 0x33f741b2 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#11 0x304b4388 in -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] ()
#12 0x3050768a in -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] ()
#13 0x3049c2b0 in -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] ()
#14 0x304cb186 in -[NSManagedObjectContext save:] ()
#15 0x00006d5a in -[MyAppViewController goToMain] (self=0x11b730, _cmd=0x174b3) at /Users/Me/Projects/MyApp/Classes/MyAppViewController.m:611
2010-09-15 17:37:10.053 MyApp[1273:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray removeObjectAtIndex:]: index (0) beyond bounds (0)'
2010-09-15 17:37:10.066 MApp[1273:207] Stack: (
853417245,
845594132,
852966195,
852966099,
............
.............
The error is coming from the fetchedResults array of the FRC. I suspect this is caused by you not implementing the FRC delegate methods properly such that when the tableview tries to update, it tries to access the zero index of an empty array.
When you have an FRC attached to any context, the FRC will update itself automatically when you make any change to context such as deleting an object (that is what the notifications in the trace stack are doing, telling the FRC to update.)