A DialogViewController with RefreshRequested and EntryElement crash when text entered - xamarin.ios

A DialogViewController contains an EntryElement and RefreshRequested handler is set (see code below).
Run in the simulator, debug mode, type some quick random text (containing spaces) in the EntryElement. Crash will follow.
What I am doing wrong ?
I guess this is a bug in DialogViewController not retaining some images that is garbage collected.
Is there a switch to trace garbage collector and removed objects ?
the offending code :
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
UINavigationController navController;
DialogViewController dv ;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
navController = new UINavigationController();
var root = new RootElement("Test") {
new Section("Quick type some text") {
new EntryElement("that contains spaces", string.Empty, string.Empty)
}
};
dv = new DialogViewController(root, true);
dv.RefreshRequested += HandleDvRefreshRequested; // comment this line fixes the bug
window.MakeKeyAndVisible ();
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0)) {
window.RootViewController = navController;
} else {
window.AddSubview (navController.View);
}
return true;
}
void HandleDvRefreshRequested (object sender, EventArgs e)
{
dv.ReloadComplete();
}
}
Starting iOS simulator 5.0
Launching application
Application launched. PID = 4730
Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll [External]
Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll [External]
Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/System.dll [External]
Thread started:
Loaded assembly: /Users/user/Documents/iphone-cinetoile/Cinetoile.UI2/bin/iPhoneSimulator/Debug/MyApp.exe
Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/MonoTouch.Dialog-1.dll [External]
Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Security.dll [External]
Loaded assembly: /Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll [External]
Stacktrace:
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at MyApp.Application.Main (string[]) [0x00000] in /Users/user/Documents/MyApp/Main.cs:17
at (wrapper runtime-invoke) .runtime_invoke_void_object (object,intptr,intptr,intptr)
Native stacktrace:
0 MyApp 0x000908ec mono_handle_native_sigsegv + 284
1 MyApp 0x00005c88 mono_sigsegv_signal_handler + 248
2 libSystem.B.dylib 0x9141905b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 ??? 0x92c013ef 0x0 + 2462061551
5 ??? 0x92c011ee 0x0 + 2462061038
6 ??? 0x987a313c 0x0 + 2558144828
7 CoreGraphics 0x91b49e20 CGDataProviderRetain + 22
8 ??? 0x9880c456 0x0 + 2558575702
9 ImageIO 0x9754a0d2 CGImageReadCreateWithProvider + 185
10 ImageIO 0x97549fee CGImageSourceCreateWithDataProvider + 186
11 CoreGraphics 0x013c0d2f CGImageCreateWithPNGDataProvider + 87
12 WebCore 0x073ca2a5 WKGraphicsCreateImageFromBundleWithName + 373
13 WebCore 0x06c1c5bd _ZN7WebCore15GraphicsContext23drawLineForTextCheckingERKNS_10FloatPointEfNS0_21TextCheckingLineStyleE + 369
14 WebCore 0x06cf6e84 _ZN7WebCore13InlineTextBox28paintSpellingOrGrammarMarkerEPNS_15GraphicsContextERKNS_10FloatPointERKNS_14DocumentMarkerEPNS_11RenderStyleERKNS_4FontEb + 1684
15 WebCore 0x06cf6fb9 _ZN7WebCore13InlineTextBox20paintDocumentMarkersEPNS_15GraphicsContextERKNS_10FloatPointEPNS_11RenderStyleERKNS_4FontEb + 297
16 WebCore 0x06cf33fc _ZN7WebCore13InlineTextBox5paintERNS_9PaintInfoEiiii + 6490
17 WebCore 0x06cec3cd _ZN7WebCore13InlineFlowBox5paintERNS_9PaintInfoEiiii + 1065
18 WebCore 0x0724d24c _ZN7WebCore13RootInlineBox5paintERNS_9PaintInfoEiiii + 64
19 WebCore 0x071a8e2a _ZNK7WebCore17RenderLineBoxList5paintEPNS_20RenderBoxModelObjectERNS_9PaintInfoEii + 638
20 WebCore 0x07142089 _ZN7WebCore11RenderBlock11paintObjectERNS_9PaintInfoEii + 369
21 WebCore 0x0714248f _ZN7WebCore11RenderBlock5paintERNS_9PaintInfoEii + 307
22 WebCore 0x07141615 _ZN7WebCore11RenderBlock13paintChildrenERNS_9PaintInfoEii + 467
23 WebCore 0x071420ab _ZN7WebCore11RenderBlock11paintObjectERNS_9PaintInfoEii + 403
24 WebCore 0x0714248f _ZN7WebCore11RenderBlock5paintERNS_9PaintInfoEii + 307
25 WebCore 0x07141615 _ZN7WebCore11RenderBlock13paintChildrenERNS_9PaintInfoEii + 467
26 WebCore 0x071420ab _ZN7WebCore11RenderBlock11paintObjectERNS_9PaintInfoEii + 403
27 WebCore 0x0714248f _ZN7WebCore11RenderBlock5paintERNS_9PaintInfoEii + 307
28 WebCore 0x07141615 _ZN7WebCore11RenderBlock13paintChildrenERNS_9PaintInfoEii + 467
29 WebCore 0x071420ab _ZN7WebCore11RenderBlock11paintObjectERNS_9PaintInfoEii + 403
30 WebCore 0x0714248f _ZN7WebCore11RenderBlock5paintERNS_9PaintInfoEii + 307
31 WebCore 0x071961b0 _ZN7WebCore11RenderLayer10paintLayerEPS0_PNS_15GraphicsContextERKNS_7IntRectEjPNS_12RenderObjectEPN3WTF7HashMapIPNS_24OverlapTestRequestClientES4_NS9_7PtrHashISC_EENS9_10HashTraitsISC_EENSF_IS4_EEEEj + 3684
32 WebCore 0x0719648c _ZN7WebCore11RenderLayer10paintLayerEPS0_PNS_15GraphicsContextERKNS_7IntRectEjPNS_12RenderObjectEPN3WTF7HashMapIPNS_24OverlapTestRequestClientES4_NS9_7PtrHashISC_EENS9_10HashTraitsISC_EENSF_IS4_EEEEj + 4416
33 WebCore 0x071973bb _ZN7WebCore11RenderLayer5paintEPNS_15GraphicsContextERKNS_7IntRectEjPNS_12RenderObjectE + 101
34 WebCore 0x06bef809 _ZN7WebCore9FrameView13paintContentsEPNS_15GraphicsContextERKNS_7IntRectE + 591
35 WebKit 0x067a51d0 -[WebFrame(WebInternal) _drawRect:contentsOnly:] + 368
36 WebKit 0x067cc83c -[WebHTMLView drawSingleRect:] + 124
37 WebKit 0x067cc786 -[WebHTMLView drawRect:] + 118
38 WebCore 0x07392c2f _ZL12drawCallbackP6WKView6CGRectPv + 95
39 WebCore 0x073cd52c _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 492
40 WebCore 0x073cd61f _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 735
41 WebCore 0x073cd61f _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 735
42 WebCore 0x073cd61f _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 735
43 WebCore 0x073cd61f _ZL11_WKViewDrawP9CGContextP6WKView6CGRectb + 735
44 WebCore 0x073cd80e WKViewDisplayRect + 158
45 WebCore 0x073cead0 WKWindowDrawRect + 48
46 WebCore 0x0735daf0 _ZN7WebCore9TileCache9drawLayerEP9TileLayerP9CGContext + 880
47 WebCore 0x07362af1 -[TileLayer drawInContext:] + 49
48 QuartzCore 0x0417212d _ZL16backing_callbackP9CGContextPv + 88
49 QuartzCore 0x0409215d CABackingStoreUpdate_ + 2636
50 QuartzCore 0x04171fd2 _ZN2CA5Layer8display_Ev + 1370
51 QuartzCore 0x0415fcf1 -[CALayer _display] + 33
52 QuartzCore 0x04166281 _ZN2CA5Layer7displayEv + 165
53 QuartzCore 0x0415fd17 -[CALayer display] + 33
54 QuartzCore 0x04169c5c _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 256
55 QuartzCore 0x040effb9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 395
56 QuartzCore 0x040f1ea6 _ZN2CA11Transaction6commitEv + 374
57 QuartzCore 0x040f1580 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 80
58 CoreFoundation 0x011959ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
59 CoreFoundation 0x0112c670 __CFRunLoopDoObservers + 384
60 CoreFoundation 0x010f84f6 __CFRunLoopRun + 1174
61 CoreFoundation 0x010f7db4 CFRunLoopRunSpecific + 212
62 CoreFoundation 0x010f7ccb CFRunLoopRunInMode + 123
63 GraphicsServices 0x04789879 GSEventRunModal + 207
64 GraphicsServices 0x0478993e GSEventRun + 114
65 UIKit 0x02190a9b UIApplicationMain + 1175
66 ??? 0x0cda47fd 0x0 + 215631869
67 ??? 0x0cc78ea0 0x0 + 214404768
68 ??? 0x0cc78b98 0x0 + 214403992
69 ??? 0x0cc78cee 0x0 + 214404334
70 MyApp 0x00009ff2 mono_jit_runtime_invoke + 722
71 MyApp 0x00169eee mono_runtime_invoke + 126
72 MyApp 0x0016dfd4 mono_runtime_exec_main + 420
73 MyApp 0x001733f5 mono_runtime_run_main + 725
74 MyApp 0x000671f5 mono_jit_exec + 149
75 MyApp 0x002116c9 main + 2825
76 MyApp 0x00003045 start + 53
=================================================================
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.
=================================================================

It's a case of Autocorrection strikes back, aka bug #325 (and quite a few duplicates) and it's not MonoTouch specific.
Something, deep down, the simulated iOS gets corrupted and shows up while it wants to draw it's little red line to show something is misspelled.
This will only happen in the simulator and only when an UITextField has auto-correction enabled. Turning it off like this:
new EntryElement("that contains spaces", string.Empty, string.Empty) {
AutocorrectionType = UITextAutocorrectionType.No
}
will solve the issue (and you can do it only for your simulator builds with a #define).

Related

Core Data, NSPredicate causes NSInvalidArgumentException

I am calling this code on a background thread.
backgroundContext.performAndWait {
let fetchRequest:NSFetchRequest<BlogPost> = BlogPost.fetchRequest()
fetchRequest.predicate = NSPredicate.init(format: "postid=%#", argumentArray: [someInt64Value]) // this line creates an exception
_ = try? fetchRequest.execute()
....
}
If I remove the predicate, it works fine. The same predicate works just fine if used inside a fetchResultController. postid is Int64 but if I changed the predicate to any other key it would give the same NSInvalidArgumentException
This is very similar to Core Data Error - NSDate localizedCaseInsensitiveCompare: unrecognised selector sent to instance
2016-10-11 21:58:13.918 BlogClient[44494:13192129] -[_SwiftValue longLongValue]: unrecognized selector sent to instance 0x618000243cc0
2016-10-11 21:58:13.922 BlogClient[44494:13192129] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue longLongValue]: unrecognized selector sent to instance 0x618000243cc0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f59534b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ebd921e objc_exception_throw + 48
2 CoreFoundation 0x000000010f604f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010f51ac15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010f51a798 _CF_forwarding_prep_0 + 120
5 CoreData 0x000000010f09762e -[NSSQLiteConnection execute] + 2270
6 CoreData 0x000000010f0aeaba newFetchedRowsForFetchPlan_MT + 1658
7 CoreData 0x000000010f274467 _executeFetchRequest + 55
8 CoreData 0x000000010f1f3be5 -[NSSQLFetchRequestContext executeRequestUsingConnection:] + 53
9 CoreData 0x000000010f220eb7 __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 215
10 libdispatch.dylib 0x0000000112b8b0cd _dispatch_client_callout + 8
11 libdispatch.dylib 0x0000000112b6830a _dispatch_barrier_sync_f_invoke + 340
12 CoreData 0x000000010f220d8c -[NSSQLDefaultConnectionManager handleStoreRequest:] + 236
13 CoreData 0x000000010f22861f -[NSSQLCoreDispatchManager routeStoreRequest:] + 351
14 CoreData 0x000000010f1ab7d9 -[NSSQLCore dispatchRequest:withRetries:] + 233
15 CoreData 0x000000010f1a711d -[NSSQLCore processFetchRequest:inContext:] + 93
16 CoreData 0x000000010f09dcf8 -[NSSQLCore executeRequest:withContext:error:] + 568
17 CoreData 0x000000010f191b79 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 5609
18 CoreData 0x000000010f189966 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 390
19 CoreData 0x000000010f09d87e -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 654
20 CoreData 0x000000010f09be24 -[NSManagedObjectContext executeFetchRequest:error:] + 548
21 CoreData 0x000000010f0e154f -[NSManagedObjectContext(_NestedContextSupport) _parentObjectsForFetchRequest:inContext:error:] + 431
22 CoreData 0x000000010f1626b3 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 611
23 CoreData 0x000000010f0e133d internalBlockToNSManagedObjectContextPerform + 93
24 libdispatch.dylib 0x0000000112b8b0cd _dispatch_client_callout + 8
25 libdispatch.dylib 0x0000000112b6d5e5 _dispatch_barrier_sync_f_slow_invoke + 617
26 libdispatch.dylib 0x0000000112b8b0cd _dispatch_client_callout + 8
27 libdispatch.dylib 0x0000000112b6b8d6 _dispatch_main_queue_callback_4CF + 406
28 CoreFoundation 0x000000010f5594f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
29 CoreFoundation 0x000000010f51ef8d __CFRunLoopRun + 2205
30 CoreFoundation 0x000000010f51e494 CFRunLoopRunSpecific + 420
31 GraphicsServices 0x0000000113b72a6f GSEventRunModal + 161
32 UIKit 0x000000010f9b8f34 UIApplicationMain + 159
33 BlogClient 0x000000010e5a8bdf main + 111
34 libdyld.dylib 0x0000000112bd768d start + 1
35 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I found the issue. Passing an Int64 confuses the argumentArray, casting it to Int fixes the issue.
This seems to be a bug in NSPredicate() filed as radar 28749194
let id:Int64 = 5785905063264256 // Making this Int works
#objc class Test:NSObject {
let postid = id
}
let predicate = NSPredicate(format: "postid == %#"
, argumentArray: [id])
let mytest = Test()
predicate.evaluate(with: mytest) //false but should be true

CoreData fetchRequest results in uncaught exception

In CoreData I want to fetch an element by a key. However executing the fetch request results in unrecognized selector sent to instance. The excerpt from my code is shown below, which fails on the last line. managedObjectContext is a valid instance, as I'm also that one to insert new instances. Could this be some incompatibility be with Swift's Int64 and CoreData's Integer 64?
var error : NSError?
var request = NSFetchRequest(entityName: "Node")
var nodeId = NSNumber(longLong: Int64(46763376))
request.predicate = NSPredicate(format: "id = %#", [nodeId])
var nodes = managedObjectContext.executeFetchRequest(request, error: &error)
Entity definition in the datamodel:
Node entity is defined in Swift as:
class Node : NSManagedObject {
#NSManaged var id: NSNumber
#NSManaged var lat: NSNumber
#NSManaged var lon: NSNumber
#NSManaged var tags: NSMutableSet
#NSManaged var ways: NSMutableSet
func description() -> String {
return "Node(id=\(id), lat=\(lat), lon=\(lon))"
}
}
Stack trace:
2014-06-30 08:27:58.238 SwiftApp[35316:1660108] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtCSs22ContiguousArrayStorage000000000B6E69C4 longLongValue]: unrecognized selector sent to instance 0xd7d0018'
*** First throw call stack:
(
0 CoreFoundation 0x00864646 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x0218f8e3 objc_exception_throw + 44
2 CoreFoundation 0x0086b575 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x007b6407 ___forwarding___ + 1047
4 CoreFoundation 0x007b5fce _CF_forwarding_prep_0 + 14
5 CoreData 0x0035a125 -[NSSQLiteConnection execute] + 1349
6 CoreData 0x0036e197 -[NSSQLChannel selectRowsWithStatement:] + 119
7 CoreData 0x0037767d newFetchedRowsForFetchPlan_MT + 1741
8 CoreData 0x00362723 -[NSSQLCore newRowsForFetchPlan:] + 403
9 CoreData 0x00361d85 -[NSSQLCore objectsForFetchRequest:inContext:] + 709
10 CoreData 0x00361740 -[NSSQLCore executeRequest:withContext:error:] + 448
11 CoreData 0x0045c6a5 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 2917
12 CoreData 0x00465be8 internalBlockToNSPersistentStoreCoordinatorPerform + 72
13 libdispatch.dylib 0x026a6488 _dispatch_client_callout + 14
14 libdispatch.dylib 0x0268ea38 _dispatch_barrier_sync_f_invoke + 124
15 libdispatch.dylib 0x0268e2c0 dispatch_barrier_sync_f + 89
16 CoreData 0x004574b3 _perform + 99
17 CoreData 0x00361345 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1525
18 CoreData 0x0035f575 -[NSManagedObjectContext executeFetchRequest:error:] + 597
19 SwiftApp 0x000189b6 _TFC8SwiftApp11AppDelegate6parserfS0_FTGSQCSo11NSXMLParser_15didStartElementGSQSS_12namespaceURIGSQSS_13qualifiedNameGSQSS_10attributesGSQCSo12NSDictionary__T_ + 18086
20 SwiftApp 0x0001a335 _TToFC8SwiftApp11AppDelegate6parserfS0_FTGSQCSo11NSXMLParser_15didStartElementGSQSS_12namespaceURIGSQSS_13qualifiedNameGSQSS_10attributesGSQCSo12NSDictionary__T_ + 1221
21 Foundation 0x00d1c00d _startElementNs + 3178
22 libxml2.2.dylib 0x02e8333d xmlParseStartTag2 + 4426
23 libxml2.2.dylib 0x02e860b2 xmlParseTryOrFinish + 3828
24 libxml2.2.dylib 0x02e84fc2 xmlParseChunk + 952
25 Foundation 0x00d19054 -[NSXMLParser parseData:] + 314
26 Foundation 0x00d194f5 -[NSXMLParser parseFromStream] + 276
27 Foundation 0x00d19639 -[NSXMLParser parse] + 33
28 SwiftApp 0x00012b72 _TFC8SwiftApp11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqCSo12NSDictionary__Sb + 1970
29 SwiftApp 0x000133a5 _TToFC8SwiftApp11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqCSo12NSDictionary__Sb + 101
30 UIKit 0x0105bb37 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 291
31 UIKit 0x0105c875 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2920
32 UIKit 0x0105fa33 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1507
33 UIKit 0x01077eb8 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
34 UIKit 0x0105e77e -[UIApplication workspaceDidEndTransaction:] + 29
35 FrontBoardServices 0x0381bf1f -[FBSWorkspace clientEndTransaction:] + 87
36 FrontBoardServices 0x038234ed __53-[FBSWorkspaceClient _queue_handleTransactionBookEnd]_block_invoke + 49
37 CoreFoundation 0x00788f90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
38 CoreFoundation 0x0077e133 __CFRunLoopDoBlocks + 195
39 CoreFoundation 0x0077d898 __CFRunLoopRun + 936
40 CoreFoundation 0x0077d22b CFRunLoopRunSpecific + 443
41 CoreFoundation 0x0077d05b CFRunLoopRunInMode + 123
42 UIKit 0x0105e095 -[UIApplication _run] + 571
43 UIKit 0x010616e5 UIApplicationMain + 1526
44 SwiftApp 0x0001e471 top_level_code + 97
45 SwiftApp 0x0001eaeb main + 43
46 libdyld.dylib 0x026d0ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The error is here:
request.predicate = NSPredicate(format: "id = %#", [nodeId])
because you pass an array to the "variable argument list" form of predicateWithFormat.
Both of these versions should work:
request.predicate = NSPredicate(format: "id = %#", nodeId)
request.predicate = NSPredicate(format: "id = %#", argumentArray: [nodeId])
Remark: The NSManagedObject documentation states that you are "strongly discouraged"
from overriding the description method in your subclasses.

UIAlertViewStyleSecureTextInput not working with ios 7

i have a issues to use a uialertView with a TextFiled in ios 7.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"title" message:nil delegate:self cancelButtonTitle:#"ok" otherButtonTitles:#"cancel", nil];
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[alert show];
but in new SDK of ios 7 Creasing and Cresh Can-sol like
AssertMacros: queueEntry, file: /SourceCache/IOKitUser_Sim/IOKitUser-920.1.11/hid.subproj/IOHIDEventQueue.c, line: 512
2013-09-09 10:39:51.659 Food.de[912:a0b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x037a16f4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02cc08b6 objc_exception_throw + 44
2 CoreFoundation 0x03742616 -[__NSArrayM objectAtIndex:] + 246
3 Food.de 0x0006583f -[HomeViewController addButtonToKeyboard] + 735
4 Food.de 0x00065e8e -[HomeViewController keyboardDidShow:] + 238
5 Foundation 0x02787089 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
6 CoreFoundation 0x037fd634 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
7 CoreFoundation 0x0375513b _CFXNotificationPost + 2859
8 Foundation 0x026c0de1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
9 UIKit 0x01cb8e97 -[UIInputViewTransition postNotificationsForTransitionEnd] + 1054
10 UIKit 0x01caf4b8 __53-[UIPeripheralHost(UIKitInternal) executeTransition:]_block_invoke1329 + 455
11 UIKit 0x0188dc15 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 306
12 UIKit 0x018778bc -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 267
13 UIKit 0x01877ba4 -[UIViewAnimationState animationDidStop:finished:] + 80
14 QuartzCore 0x00cb2e84 _ZN2CA5Layer23run_animation_callbacksEPv + 304
15 libdispatch.dylib 0x0316b4b0 _dispatch_client_callout + 14
16 libdispatch.dylib 0x03159766 _dispatch_main_queue_callback_4CF + 340
17 CoreFoundation 0x03806b6e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
18 CoreFoundation 0x037477eb __CFRunLoopRun + 1963
19 CoreFoundation 0x03746bf3 CFRunLoopRunSpecific + 467
20 CoreFoundation 0x03746a0b CFRunLoopRunInMode + 123
21 GraphicsServices 0x03e8fa27 GSEventRunModal + 192
22 GraphicsServices 0x03e8f84e GSEventRun + 104
23 UIKit 0x0182bf0b UIApplicationMain + 1225
24 Food.de 0x00006c1d main + 141
25 Food.de 0x00006b85 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
if any one develop with ios 7 and know how to solve this problem then help .
.....
if alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
my xcode Version 5.0 (5A11386k)
is not working with ios 7 then we use old strategy like we do for ios 5 ?
thanks .
The problem is on your HomeViewController. You have a
[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]
This means you are trying to access an index that doesn't exists, I think on line 246

Monotouch Crash with UIWebView

I am getting random crashes with UIWebView. The only thing I have is the crash message. Hopefully this is enough to give a clue as to whats causing it. I am using my own webview delegate and subclassing SizingSource. Thanks.
Stacktrace:
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at app.Application.Main (string[]) [0x00000] in /Users/vbisbest/Projects/app/MineChat/Main.cs:17
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
0 MineChat 0x00095f7c mono_handle_native_sigsegv + 284
1 MineChat 0x0000be98 mono_sigsegv_signal_handler + 248
2 libsystem_c.dylib 0x9a6c759b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 UIKit 0x02914aad -[UIWebViewWebViewDelegate webView:resource:didFinishLoadingFromDataSource:] + 63
5 CoreFoundation 0x0134a1bd __invoking___ + 29
6 CoreFoundation 0x0134a0d6 -[NSInvocation invoke] + 342
7 CoreFoundation 0x0134a24a -[NSInvocation invokeWithTarget:] + 74
8 WebKit 0x06b88881 -[_WebSafeForwarder forwardInvocation:] + 257
9 CoreFoundation 0x01345cf9 ___forwarding___ + 905
10 CoreFoundation 0x0134594e _CF_forwarding_prep_0 + 14
11 CoreFoundation 0x0134a1bd __invoking___ + 29
12 CoreFoundation 0x0134a0d6 -[NSInvocation invoke] + 342
13 WebCore 0x079c6483 _ZL11SendMessageP12NSInvocation + 35
14 WebCore 0x079c5ff8 _ZL20HandleDelegateSourcePv + 104
15 CoreFoundation 0x012d9f3f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x012d996f __CFRunLoopDoSources0 + 239
17 CoreFoundation 0x012fc734 __CFRunLoopRun + 964
18 CoreFoundation 0x012fbf44 CFRunLoopRunSpecific + 276
19 CoreFoundation 0x012fbe1b CFRunLoopRunInMode + 123
20 GraphicsServices 0x04d237e3 GSEventRunModal + 88
21 GraphicsServices 0x04d23668 GSEventRun + 104
22 UIKit 0x0273965c UIApplicationMain + 1211
23 ??? 0x0e39bf15 0x0 + 238665493
24 ??? 0x0e398b78 0x0 + 238652280
25 ??? 0x0e397ea8 0x0 + 238649000
26 ??? 0x0e39801e 0x0 + 238649374
27 MineChat 0x00010252 mono_jit_runtime_invoke + 722
28 MineChat 0x0017478e mono_runtime_invoke + 126
29 MineChat 0x00178be4 mono_runtime_exec_main + 420
30 MineChat 0x00178f55 mono_runtime_run_main + 725
31 MineChat 0x0006ba65 mono_jit_exec + 149
32 MineChat 0x0021f65d main + 2013
33 MineChat 0x00003125 start + 53
34 ??? 0x00000004 0x0 + 4
=================================================================
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.
=================================================================
void HandleLoadFinished (object sender, EventArgs e)
{
try
{
// New message has been added, customize the cell and size it properly
UIWebView webView = (UIWebView)sender;
webView.ScrollView.ScrollEnabled = false;
// Get the height of the content
float height = float.Parse(webView.EvaluateJavascript("document.height"));
// Redraw the webview frame to the size of the content
webView.Frame = new RectangleF(0,0,this.View.Frame.Width, height);
webView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
// Create the dialog element with the new view
//UIViewElement viewElement = new UIViewElement("", webView ,false);
WebViewElement viewElement = new WebViewElement("", webView ,false);
string html = webView.EvaluateJavascript("document.body.innerHTML");
viewElement.HTML = html;
viewElement.WebView = webView;
viewElement.Tapped += delegate()
{
if(MessageTapped!=null)
{
MessageTapped(viewElement.HTML);
}
};
// Add it to the section
messageSection.Add(viewElement);
CustomSizingSource customSizingSource = (CustomSizingSource)this.TableView.Source;
if(customSizingSource.PinToBottom)
{
var lastIndexPath = viewElement.IndexPath;
if(lastIndexPath!=null)
{
this.TableView.ScrollToRow( lastIndexPath, UITableViewScrollPosition.Bottom, true);
}
}
}
catch(Exception ex)
{
Console.WriteLine("Error message finished loading: " + ex.Message);
}
}

App is crashing in a certain line, Why?

My real code is full of NSLog's,
the following line is the reason for he crash but I don't understand why
NSString *newDir = [documentsDirectory
stringByAppendingPathComponent:file];
Here is the whole method:
- (void)viewDidLoad {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray* newArray= [[NSArray alloc]init];
newArray= [fileManager contentsOfDirectoryAtURL:[NSURL fileURLWithPath:#"/Users/admin/Library/FotoAppFotos/"]
includingPropertiesForKeys:[NSArray arrayWithObject:NSURLNameKey] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
categories= [NSMutableArray arrayWithArray: newArray];
for(NSString *file in categories) {
NSString *newDir = [documentsDirectory stringByAppendingPathComponent:file]; // in this line the app crashes
[categories addObject:newDir]; //categories
}
[super viewDidLoad];
}
As mentioned the NSLog print of documentsDirectory and file are:
documentsDirectory: /Users/admin/Library/Application Support/iPhone
Simulator/4.3/Applications/D5AB6F90-0420-4A66-B141-D27AB2C11C3C/Documents
file://localhost/Users/admin/Library/FotoAppFotos/Audio/
The whole crash log is:
2011-11-09 09:21:42.989 TestTest[543:207] -[NSURL length]: unrecognized selector sent to instance 0x5c07df0
2011-11-09 09:21:42.992 TestTest[543:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x5c07df0'
*** Call stack at first throw:
(
0 CoreFoundation 0x0102b5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0117f313 objc_exception_throw + 44
2 CoreFoundation 0x0102d0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00f9c966 ___forwarding___ + 966
4 CoreFoundation 0x00f9c522 _CF_forwarding_prep_0 + 50
5 Foundation 0x0002b1ad -[NSPathStore2 stringByAppendingPathComponent:] + 211
6 TestTest 0x00003244 -[Produktpalette viewDidLoad] + 535
7 UIKit 0x0036f089 -[UIViewController view] + 179
8 UIKit 0x0060ca40 -[UIPopoverController _setupIncomingViewController:presenting:animated:] + 143
9 UIKit 0x0060be26 -[UIPopoverController initWithContentViewController:] + 321
10 TestTest 0x00002540 -[TestTestViewController produktpalette:] + 151
11 UIKit 0x002bf4fd -[UIApplication sendAction:to:from:forEvent:] + 119
12 UIKit 0x004d1cc3 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
13 UIKit 0x002bf4fd -[UIApplication sendAction:to:from:forEvent:] + 119
14 UIKit 0x0034f799 -[UIControl sendAction:to:forEvent:] + 67
15 UIKit 0x00351c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
16 UIKit 0x003507d8 -[UIControl touchesEnded:withEvent:] + 458
17 UIKit 0x002e3ded -[UIWindow _sendTouchesForEvent:] + 567
18 UIKit 0x002c4c37 -[UIApplication sendEvent:] + 447
19 UIKit 0x002c9f2e _UIApplicationHandleEvent + 7576
20 GraphicsServices 0x01983992 PurpleEventCallback + 1550
21 CoreFoundation 0x0100c944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
22 CoreFoundation 0x00f6ccf7 __CFRunLoopDoSource1 + 215
23 CoreFoundation 0x00f69f83 __CFRunLoopRun + 979
24 CoreFoundation 0x00f69840 CFRunLoopRunSpecific + 208
25 CoreFoundation 0x00f69761 CFRunLoopRunInMode + 97
26 GraphicsServices 0x019821c4 GSEventRunModal + 217
27 GraphicsServices 0x01982289 GSEventRun + 115
28 UIKit 0x002cdc93 UIApplicationMain + 1160
29 TestTest 0x00001c2a main + 84
30 TestTest 0x00001bcd start + 53
)
terminate called after throwing an instance of 'NSException'
Thank you for any help and presumption in advance
The hint comes from:
[NSURL length]: unrecognized selector sent to instance
If you are working on iOS, sorry to tell that :
This method is unimplemented in iOS, so it performs no operation.
Somebody has similar problem .

Resources